Get the App
SLTechnology News&Howtos  ›  Development  › 

How Java converts Excel to PDF based on Spire.Cloud.Excel

Shulou Source: shulou.com Published: 2022-06-02 12:55:35 10月01日 Update

This article will explain in detail how Java converts Excel to PDF based on Spire.Cloud.Excel. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Spire.Cloud.Excel.Sdk provides GeneralApi interface and WorkbookApi interface to support the conversion of local Excel and cloud Excel documents to ODS, PDF, XPS, PCL, PS and other formats. Taking the conversion from Excel table to PDF as an example, this paper introduces the steps and methods of format conversion.

Necessary steps:

Step 1:jar file download and import. You can download the jar; through the "download Center" or install and import it through the maven warehouse. Refer to the installation method.

Step 2:ID and Key acquisition. You need to create an account in the cloud and an application in the "my applications" section to get App ID and App Key.

Step 3: when converting a cloud Excel document to PDF, you need to upload the Excel document in the "document Management" section first.

Note: accounts created in the cloud can be tried out for 10,000 calls and 2GB of document memory for free.

[example 1] convert a local Excel document to PDF

Import spire.cloud.excel.sdk.ApiException; import spire.cloud.excel.sdk.api.GeneralApi; import spire.cloud.excel.sdk.model.ExportFormat; import java.io.File; public class ExcelToPDF {private static String appId = "App ID"; private static String appKey = "App Key"; public static void main (String [] args) throws ApiException {/ / create GeneralApi instance and configure account information GeneralApi generalApi = new GeneralApi (appId, appKey) / / configure related parameters String format = ExportFormat.PDF.toString (); String inputFilePath = "test.xlsx"; File data = new File (inputFilePath); String outputFilePath = "ToPDF.pdf"; String password = null; / / call the putWorkbookConvert API to save the document as PDF generalApi.putWorkbookConvert (format,outputFilePath,data, password);}}

[example 2] convert cloud Excel documents to PDF

Import spire.cloud.excel.sdk.ApiException; import spire.cloud.excel.sdk.api.WorkbookApi; import spire.cloud.excel.sdk.model.ExportFormat; import spire.cloud.excel.sdk.model.ExportOptions; public class ExcelToPDF2 {private static String appId = "App ID"; private static String appKey = "App Key"; public static void main (String [] args) throws ApiException {/ / create WorkbookApi instance and configure account information WorkbookApi workbookApi = new WorkbookApi (appId, appKey) / / configure related parameters String name= "test.xlsx"; String outputFilePath = "ToPDF2.pdf"; String format = ExportFormat.PDF.toString (); ExportOptions options = null; String storage = null; String inputFolder = "input"; String password = null / / call putWorkbookSaveAs API to save the document as PDF workbookApi.putWorkbookSaveAs (name, outputFilePath, format, options, password, storage, inputFolder);}}

The document conversion results can be viewed in the document Management section, as follows:

This is the end of the article on "how Java converts Excel into PDF based on Spire.Cloud.Excel". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Documentation cloud step interface account configuration section article information parameter instance method more format example reference management good practical necessary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS Shulou Technology MySQL MariaDB