Convert Multiple CSV Files into a Single XLSX Spreadsheet in Ruby
The CSV data storage format is popular among developers for its simple design, efficient importing, and broad editing compatibility. However, if you need to share information with customers or partners, Excel is easier to read and will allow you to add advanced features such as graphs and formulas. By utilizing this API in Ruby, you will be able to automatically convert up to 10 CSV files into a single Excel spreadsheet, with a tabular worksheet corresponding to each CSV file.
First, we will add the Ruby client to our Gemfile:
gem 'cloudmersive-convert-api-client', '~> 2.1.6'
After the client has been added, you can call the conversion 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'
endapi_instance = CloudmersiveConvertApiClient::ConvertDocumentApi.newinput_file1 = File.new('/path/to/inputfile') # File | First input file to perform the operation on.input_file2 = File.new('/path/to/inputfile') # File | Second input file to perform the operation on.opts = {
input_file3: File.new('/path/to/inputfile'), # File | Third input file to perform the operation on.
input_file4: File.new('/path/to/inputfile'), # File | Fourth input file to perform the operation on.
input_file5: File.new('/path/to/inputfile'), # File | Fifth input file to perform the operation on.
input_file6: File.new('/path/to/inputfile'), # File | Sixth input file to perform the operation on.
input_file7: File.new('/path/to/inputfile'), # File | Seventh input file to perform the operation on.
input_file8: File.new('/path/to/inputfile'), # File | Eighth input file to perform the operation on.
input_file9: File.new('/path/to/inputfile'), # File | Ninth input file to perform the operation on.
input_file10: File.new('/path/to/inputfile'), # File | Tenth input file to perform the operation on.
worksheet_names: 'worksheet_names_example' # String | Optional; Specify the name of each CSV's worksheet in order, separated with commas (e.g. \"worksheet1,worksheet2,worksheet3\"). Defaults to the names of the input CSV files. Recommended when inputting the files directly, without file names.
}begin
#Convert Multiple CSV Files into a Single XLSX Spreadsheet
result = api_instance.convert_document_csv_multi_to_xlsx(input_file1, input_file2, opts)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ConvertDocumentApi->convert_document_csv_multi_to_xlsx: #{e}"
end