The spreadsheet software is commonly used to create budgets, produce graphs and charts, and for storing and sorting data. They are also popular in businesses to forecast future performance, calculate tax, complete basic payroll, produce charts and calculate revenues. But in order to view them, you need supporting software. However, in this article, we are going to discuss the steps to convert Excel files to PDF so that they can be viewed on any platform (without compromising their fidelity).
Excel Conversion API
Aspose.Cells Cloud is a REST-based API providing the capabilities to create, edit and render Excel files to PDF and other supported file formats. As per the scope of this, we are going to discuss the usage of Aspose.Cells Cloud SDK for .NET for Excel conversion to PDF using C# .NET. To get started, the first step is to install the Cloud SDK on the system. For more information, please visit How to install Aspose.Cloud SDKs.
Convert Excel to PDF in C#
Please follow the instructions given below to convert the Excel files available in Cloud storage to PDF format. As a result of this operation, all the worksheets within the source workbook will be converted to PDF format.
- First of all, create an instance of CellsApi class while passing ClientID and ClientSecret details as arguments
- Secondly, read the input XLSX file into stream object using File.OpenRead
- Now call the CellsWorkbookPutConvertWorkbook(..) method taking fileStream holding input excel, ouptut format details and resultant PDF name as arguments
The same excel file and resultant PDF generated in the above example can be downloaded from Book1.xlsx and Converted.pdf.
In can you only need to convert a particular worksheet, please try using the CellsWorksheetsGetWorksheet(…) method of CelslApi class.
Worksheet to PDF using cURL Command
The REST APIs can easily be accessed via cURL commands from the terminal/command shell. Since Aspose.Cells Cloud is developed as per REST architecture, so it can also be accessed via cURL commands. But before we proceed towards conversion operations, please note that our APIs are only accessible to authorized persons. So we need to generate JWT access token-based client credentials specified over Aspose.Cloud dashboard. For further details, please visit How to Obtain JWT token using a Client ID and Client Secret key.
Please execute the following command to generate a JWT access token:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=4db2f826-bf9c-42e7-8b2a-8cbca2d15553&client_secret=d757548a9f2558c39c2feebdf85b4c44" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Once we have a JWT token, please execute the following command to perform the conversion of the Excel file in request content to PDF format and save the output in Cloud storage.
curl -X PUT "https://api.aspose.cloud/v3.0/cells/convert?format=PDF&outPath=converted.pdf" \
-H "accept: multipart/form-data" \
-H "authorization: Bearer <JWT Token>" \
-H "Content-Type: multipart/form-data" \
-d {"File":{}}
Conclusion
We have discussed the conversion of Excel files to PDF format using REST API. We have also discussed that we can either convert a complete workbook or render a specific Worksheet to PDF format using the C# .NET code snippet or using the cURL command. We have also learned about the Cloud SDKs developed on top of REST APIs and since the SDKs are developed as per the MIT license, so the complete source code is available over GitHub.
Nevertheless, if you encounter any issues or you have any further queries, please feel free to contact us through the free customer support forum.
Related articles
We also recommend visiting the following links to learn about