Render Excel Data to PDF using REST API in Node.js

You can easily render Microsoft Excel spreadsheet data to PDF on the cloud. It can be useful in such a case when you have to present your data to relevant stakeholders without sharing the actual Excel data files with them. As a Node.js developer, you can render spreadsheet data from XLS or XLSX files in PDF documents programmatically on the cloud. This article will be focusing on how to render Excel data to PDF using a REST API in Node.js.

Document Viewer REST API and Node.js SDK

For rendering XLS or XLSX spreadsheets, I will be using the Node.js SDK of GroupDocs.Viewer Cloud API. It allows you to programmatically render and view all sorts of popular document and image file formats such as Word, Excel, PowerPoint, PDF, Visio, Project, Outlook, JPG, PNG, etc. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document viewer family members for the Cloud API.

You can install GroupDocs.Viewer Cloud to your Node.js application using the following command in the console:

npm install groupdocs-viewer-cloud 

Please get your Client ID and Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as demonstrated below:

Render Excel Data to PDF using a REST API in Node.js

You can render Microsoft Excel spreadsheet data to PDF by following the simple steps mentioned below:

Upload the Document

Firstly, upload the XLSX file to the cloud using the code example given below:

As a result, the XLSX file will be uploaded to Cloud Storage and will be available in the files section of your dashboard.

Render Excel to PDF using Node.js

Please follow the steps mentioned below to render Excel data to PDF programmatically.

  • Create an instance of the ViewAPI
  • Create an instance of the FileInfo
  • Provide the input file path
  • Create an instance of the ViewOptions
  • Assign fileInfo to ViewOptions
  • Set the viewFormat as “PDF”
  • Create a view request by calling the CreateViewRequest method with ViewOptions
  • Get a response by calling the createView() method with CreateViewRequest

The following code snippet shows how to render Excel data to PDF using a REST API in Node.js.

Render Excel Data to PDF using a REST API in Node.js

Render Excel Data to PDF using a REST API in Node.js

Download the Rendered File

The above code sample will save the rendered PDF file on the cloud. You can download it using the following code sample:

Render Excel to PDF With Rendering Options using Node.js

You can use specific rendering options to render Excel data into PDF programmatically by following the steps given below:

  • Create an instance of the ViewAPI
  • Provide the input file path to the FileInfo
  • Create an instance of the ViewOptions
  • Assign fileInfo and set the viewFormat as “PDF”
  • Create an instance of the PdfOptions
  • Create an instance of the SpreadsheetOptions
  • Set the SpreadsheetOptions such as textOverflowMode, renderGridLines, etc.
  • Create a view request by calling the CreateViewRequest method with ViewOptions
  • Get a response by calling the _createView() _method with CreateViewRequest

The following code snippet shows how to render Excel data to PDF with rendering options using a REST API in Node.js.

Render Excel to PDF With Rendering Options using Node.js

Render Excel to PDF With Rendering Options using Node.js

Try Online

Please try the following free online spreadsheet rendering tool, which is developed using the above API. https://products.groupdocs.app/viewer/xlsx

Conclusion

In this article, you have learned how to render Excel spreadsheet data to PDF on the cloud. You have also learned how to render Excel data to PDF with rendering options in Node.js. This article also explained how to programmatically upload the XLSX file on the cloud and then download the rendered PDF file from the cloud. You can learn more about GroupDocs.Viewer Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.

See Also