How to validate an Excel XLSX Spreadsheet in Ruby

Cloudmersive
1 min readAug 20, 2019

--

Validating Excel files becomes a trivial task using today’s lesson. Let’s do it in two steps:

  1. Install our Ruby client by adding this snippet to your Gemfile:
gem 'cloudmersive-convert-api-client', '~> 1.3.3'

2. Call the validate_document_xlsx_validation 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::ValidateDocumentApi.newinput_file = File.new("/path/to/file") # File | Input file to perform the operation on.begin
#Validate a Excel document (XLSX)
result = api_instance.validate_document_xlsx_validation(input_file)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ValidateDocumentApi->validate_document_xlsx_validation: #{e}"
end

Done! Our results include whether or not the document was valid (DocumentIsValid) as well as any errors (block usage of the file) or warnings (potential problems that do not block usage).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet