XLSB to PDF – Convert XLSB to PDF in C#

XLSB to PDF

XLSB format specifies the Excel Binary File Format and is quite popular because it can be read from and written much faster, making it extremely useful for very large spreadsheets. Furthermore, it is believed that in Excel, the XLSX generally loads 4 times longer when compared to the XLSB, and saves 2 times slower followed by 1.5 times a bigger file. However, in order to view the XLSB file, you need to use Microsoft Excel in Windows and macOS or OpenOffice Calc (multiplatform). Also, the fidelity of the document can be compromised due to the version differences.

So in order to mitigate all these problems, the conversion of these files to PDF format is a viable solution. In this article, let’s discuss the details on how we can programmatically convert XLSB to PDF format using Cloud APIs.

Excel Processing API

Aspose.Cells Cloud is a REST architecture-based Excel file processing API providing the capabilities to create, edit and transform to supported file formats. For our convenience, we are going to use Aspose.Cells Cloud SDK for .NET, which is a wrapper around Cloud API. Now in order to use the Cloud SDK, the first step is to install over the system. Please visit the following article to learn more about how to install Aspose.Cloud SDKs.

XLSB to PDF in C#

Please follow the steps given below to perform XLSB to PDF conversion using C# .NET.

Render complete XSLB to PDF

In this section, we are going to discuss the steps for converting the complete workbook to PDF format.

  • First of all, create an instance of CellsApi class while passing ClientID and ClientSecret details as arguments
  • Secondly, read the input XLSB file into stream object using File.OpenRead
  • Thirdly, upload the XLSB file to cloud storage using UploadFile(…) method of CellsApi class
  • Finally, call the CellsWorkbookGetWorkbook(..) method taking input XLSB name, ouptut format details and name of resultant PDF file

Render Worksheet to PDF

In this section, we are going to discuss the conversion of specific worksheet in XLSB workbook to PDF format.

  • The first step is to create an instance of CellsApi class while passing ClientID and ClientSecret details as arguments
  • Secondly, read the input XLSB file into stream object using File.OpenRead
  • Now upload the XLSB file to cloud storage using UploadFile(…) method of CellsApi class
  • Finally, call the CellsWorksheetsGetWorksheet(..) method which takes input XLSB name, worksheet name to be converted and resultant output file name as arguments
XLSB to PDF
Image 1:- XLSB to PDF conversion preview

The sample files used in the above example can be downloaded from the input.xlsb, completeWorkbook.pdf, and Worksheet2.pdf.

Convert XLSB to PDF using cURL Command

The cURL commands are the easiest way to access REST APIs on any platform. Since Aspose.Cells Cloud is developed according to REST architecture, so we can also access the API using the cURL commands. There are two approaches in converting the XLSB file to PDF format i.e. Converting the complete XLSB file to PDF format or converting a specific worksheet to PDF format. But before we proceed towards conversion operations, 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.

Complete XSLB to PDF

Please use the following command to render the complete XLSB file already available in Cloud storage to PDF format and save the output to cloud storage.

curl -X GET "https://api.aspose.cloud/v3.0/cells/TestCase.xlsb?format=PDF&isAutoFit=true&onlySaveTable=false&outPath=Resultant.pdf" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

In case you need to save the output in local drive, skip the outPath parameter value and use the -o parameter in the cURL command.

curl -X GET "https://api.aspose.cloud/v3.0/cells/TestCase.xlsb?format=PDF&isAutoFit=true&onlySaveTable=false" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o localSave.pdf

Convert XLSB in Request to PDF

In case you need to convert an XLSB file to be uploaded from a local drive and perform the conversion. For this purpose, we need to use PutConvertWorkBook API. In this scenario, the XLSB will not be uploaded to Cloud storage but if the value is provided against the outPath parameter, the resultant file is saved on Cloud storage.

curl -X PUT "https://api.aspose.cloud/v3.0/cells/convert?format=PDF&outPath=putConvert.pdf" \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d @TestCase.xlsb

In case we need to load the XLSB from the local drive and perform the conversion to PDF and also, want to save the output on the local drive, then skip the value for outPath parameter and use -o argument in the cURL command.

curl -X PUT "https://api.aspose.cloud/v3.0/cells/convert?format=PDF" \
-H  "accept: multipart/form-data" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d @TestCase.xlsb \
-o conveted.pdf

Selected Worksheets to PDF

In case we need to only convert selected worksheets to PDF format, please try using GetWorkSheetWithFormat API. When executing the following command, Worksheet2 will be converted to PDF only.

curl -X GET "https://api.aspose.cloud/v3.0/cells/input.xlsb/worksheets/Sheet2?format=PDF&verticalResolution=0&horizontalResolution=0" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o worksheet2.pdf

Conclusion

In this article, we have explored the steps regarding the conversion of the XLSB files to PDF format. Please note that our SDKs are open source and are developed under MIT license. The complete source code is available over GitHub. While using the API, 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 recommend visiting the following links to learn more about