Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to Convert Excel to PDF
# Convert XLS/XLSX to PDF using REST API in Ruby
# Create Conversion API instance
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Initialize convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/excel-sheets.xlsx"
@settings.format = "pdf"
# Set Spreadsheet Conversion LoadOptions
@loadOptions = GroupDocsConversionCloud::SpreadsheetLoadOptions.new
@loadOptions.hide_comments = true
loadOptions.one_page_per_sheet = true
@settings.load_options = @loadOptions
@settings.output_path = "xlsx-to-pdf"
# Convert XLSX to PDF
result = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("Excel sheets successfully converted to PDF.")

You can convert Excel XLSX to PDF documents programmatically on the cloud. In this article, you will learn how to convert Excel to PDF using REST API in Ruby.

The following topics shall be covered in this article:

Excel to PDF Conversion REST API and Ruby SDK Convert Excel to PDF using REST API in Ruby Convert Range of Pages from Excel to PDF in Ruby Convert Specific Pages of Excel to PDF in Ruby Online Excel to PDF Converter for Free

# Convert Specific Pages of Excel to PDF in Ruby
# Create necessary API instances
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Prepare convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/excel-sheets.xlsx"
@settings.format = "pdf"
@convertOptions = GroupDocsConversionCloud::PdfConvertOptions.new
@convertOptions.pages = [1, 2]
@settings.convert_options = @convertOptions
@settings.output_path = "xlsx-to-pdf"
# Convert specific pages to PDF
@response = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("Excel sheet successfully converted to PDF.")
# Convert Range of Pages from Excel XLSX to PDF in Ruby
# Create necessary API instances
@apiInstance = GroupDocsConversionCloud::ConvertApi.from_keys(@app_sid, @app_key)
# Set convert settings
@settings = GroupDocsConversionCloud::ConvertSettings.new
@settings.file_path = "xlsx-to-pdf/excel-sheets.xlsx"
@settings.format = "pdf"
@convertOptions = GroupDocsConversionCloud::PdfConvertOptions.new
@convertOptions.from_page = 1
@convertOptions.pages_count = 1
@settings.convert_options = @convertOptions
@settings.output_path = "xlsx-to-pdf"
# Finally convert range of pages XLSX to PDF file
result = @apiInstance.convert_document(GroupDocsConversionCloud::ConvertDocumentRequest.new(@settings))
puts("Excel sheets successfully converted to PDF.")
# Load the gem in your ruby application for http://api.groupdocs.cloud
require 'groupdocs_conversion_cloud'
# Get your client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
@app_sid = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
@app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment