How to convert Excel XLSX to CSV Files in Ruby

Here is a quick tutorial on using our Document Conversion API to convert XLSX files into CSV files.

Access your Gemfile and add the Cloudmersive Convert Client:

gem 'cloudmersive-convert-api-client', '~> 1.3.3'

Then all that’s left is to run convert_document_xlsx_to_csv:

# load the gem
require 'cloudmersive-convert-api-client'
# setup authorization
CloudmersiveConvertApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
end
api_instance = CloudmersiveConvertApiClient::ConvertDocumentApi.newinput_file = File.new("/path/to/file") # File | Input file to perform the operation on.begin
#Excel XLSX to CSV
result = api_instance.convert_document_xlsx_to_csv(input_file)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ConvertDocumentApi->convert_document_xlsx_to_csv: #{e}"
end

Seriously, it’s that easy. This API contains a separate function that will convert a CSV back into XLSX, as well as support for a multitude of other file formats for conversion and editing.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store