Java基于Spire Cloud Excel把Excel轉(zhuǎn)換成PDF
Spire.Cloud.Excel Sdk 提供GeneralApi接口和WorkbookApi接口,支持將本地Excel和云端Excel文檔轉(zhuǎn)換為ODS, PDF, XPS, PCL, PS等格式。本文以將Excel表格轉(zhuǎn)為PDF為例,介紹實(shí)現(xiàn)格式轉(zhuǎn)換的步驟及方法。
所需工具:Spire.Cloud.Excel.Sdk
必要步驟:
步驟1:Jar文件下載及導(dǎo)入??赏ㄟ^“下載中心”下載獲取jar;或者通過maven倉(cāng)庫(kù)安裝導(dǎo)入,具體參考安裝方法。
步驟2:ID及Key獲取。需要在云端創(chuàng)建賬號(hào),并在“我的應(yīng)用”板塊中創(chuàng)建應(yīng)用以獲得App ID及App Key。
步驟3:在將云端Excel文檔轉(zhuǎn)為PDF時(shí),需要在“文檔管理”板塊先上傳Excel文檔。
注:在云端創(chuàng)建的賬號(hào)可免費(fèi)試用1 萬次調(diào)用次數(shù)及 2G 文檔內(nèi)存。
【示例1】將本地Excel文檔轉(zhuǎn)換為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{
//創(chuàng)建GeneralApi實(shí)例并配置賬號(hào)信息
GeneralApi generalApi = new GeneralApi(appId, appKey);
//配置相關(guān)參數(shù)
String format = ExportFormat.PDF.toString();
String inputFilePath = "test.xlsx";
File data = new File(inputFilePath );
String outputFilePath = "ToPDF.pdf";
String password = null;
//調(diào)用putWorkbookConvert接口將文檔保存為PDF
generalApi.putWorkbookConvert(format,outputFilePath,data, password);
}
}
【示例2】將云端Excel文檔轉(zhuǎn)換為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 {
//創(chuàng)建WorkbookApi實(shí)例并配置賬號(hào)信息
WorkbookApi workbookApi = new WorkbookApi(appId, appKey);
//配置相關(guān)參數(shù)
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;
//調(diào)用putWorkbookSaveAs接口將文檔保存為PDF
workbookApi.putWorkbookSaveAs(name, outputFilePath, format, options, password, storage, inputFolder);
}
}
文檔轉(zhuǎn)換結(jié)果可在“文檔管理”板塊中查看,如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java 中的static關(guān)鍵字和final關(guān)鍵字的不同之處
java 中的static關(guān)鍵字和final關(guān)鍵字的不同之處,需要的朋友可以參考一下2013-03-03
java實(shí)現(xiàn)截取PDF指定頁并進(jìn)行圖片格式轉(zhuǎn)換功能
這篇文章主要介紹了java實(shí)現(xiàn)截取PDF指定頁并進(jìn)行圖片格式轉(zhuǎn)換功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
Spring?cloud網(wǎng)關(guān)gateway進(jìn)行websocket路由轉(zhuǎn)發(fā)規(guī)則配置過程
這篇文章主要介紹了Spring?cloud網(wǎng)關(guān)gateway進(jìn)行websocket路由轉(zhuǎn)發(fā)規(guī)則配置過程,文中還通過實(shí)例代碼介紹了Spring?Cloud?Gateway--配置路由的方法,需要的朋友可以參考下2023-04-04
JAVA實(shí)現(xiàn)的簡(jiǎn)單萬年歷代碼
這篇文章主要介紹了JAVA實(shí)現(xiàn)的簡(jiǎn)單萬年歷代碼,涉及Java日期操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
SpringBoot Web詳解靜態(tài)資源規(guī)則與定制化處理
這篇文章主要介紹了SpringBoot web場(chǎng)景的靜態(tài)資源規(guī)則與定制化,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-06-06
Spring Cache相關(guān)知識(shí)總結(jié)
今天帶大家學(xué)習(xí)Spring的相關(guān)知識(shí),文中對(duì)Spring Cache作了非常詳細(xì)的介紹,對(duì)正在學(xué)習(xí)Java Spring的小伙伴們很有幫助,需要的朋友可以參考下2021-05-05

