How to Convert Excel (97–2003) to CSV in Ruby

Cloudmersive
2 min readAug 26, 2021

--

Outdated file formats can be a difficult roadblock when it comes to sharing or manipulating the contents of the files. One way to remove this roadblock is converting to another, more convenient format, such as CSV. Since conversions themselves can be complicated as well, we will be showing you how to automatically convert an Excel (97–2003) file to CSV in Ruby.

We will start by adding the Ruby client to the Gemfile:

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

After this, we can input the file and API key into the following code to call the ConvertDocumentXLStoCSV function:

# 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/inputfile') # File | Input file to perform the operation on.begin
#Convert Excel XLS (97-03) Spreadsheet to CSV
result = api_instance.convert_document_xls_to_csv(input_file)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ConvertDocumentApi->convert_document_xls_to_csv: #{e}"
end

Your new CSV file will be available at the end of this short process! If you need to obtain an API key, register for a free account on the Cloudmersive website; this provides 800 calls/month across our library of APIs.

--

--

Cloudmersive

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