Spire.Cloud.Excel SDK Java提供GeneralApi接口和WorkbookApi接口,支持将本地Excel工作簿和云端Excel文档转换为ODS, PDF, XPS, PCL, PS等格式。本文将介绍如何分别调用GeneralApi接口和WorkbookApi接口将Excel 文档保存为PDF格式。
首先,请通过 Maven仓库安装Spire.Cloud.Word jar包及依赖。其次,需要在冰蓝云官网 (https://cloud.e-iceblue.cn/) 注册账号,创建我的应用程序,获得 APP ID 及 App Key。
我们为每个账户提供了2G免费内存,在”文档管理” 目录下面可以看到转换成功的PDF文档效果图:
GeneralApi接口支持将本地的Excel文档保存为云端PDF:
import java.io.File;
import spire.cloud.excel.sdk.api.GeneralApi;
import spire.cloud.excel.sdk.model.ExportFormat;
public class ExcelDemo {
private static String appId = "您的冰蓝云应用程序AppID";
private static String appKey = "您的冰蓝云应用程序AppKey";
public static void main(String[] args) throws Exception {
//创建GeneralApi实例并配置账号信息
GeneralApi generalApi = new GeneralApi(appId, appKey);
//配置相关参数
String format = ExportFormat.PDF.toString();
String inputFilePath = "Test.xlsx";
File data = new File(inputFilePath );
String outputFilePath = "GeneralApi1.pdf";
String password = null;
//调用putWorkbookConvert接口将文档保存为PDF
generalApi.putWorkbookConvert(format,outputFilePath,data, password);
}
}
WorkbookApi接口支持将云端的Excel文档保存为云端PDF:
import spire.cloud.excel.sdk.api.WorkbookApi;
import spire.cloud.excel.sdk.model.*;
public class ExcelDemo {
private static String appId = "您的冰蓝云应用程序AppID";
private static String appKey = "您的冰蓝云应用程序AppKey";
public static void main(String[] args) throws Exception {
//创建WorkbookApi实例并配置账号信息
WorkbookApi workbookApi = new WorkbookApi(appId, appKey);
//配置相关参数
String name= "Test.xlsx";
String outputFilePath = "workbookApi.pdf";
String format = ExportFormat.PDF.toString();
ExportOptions options = null;
String storage = null;
String inputFolder = "input";
String password = null;
//调用putWorkbookSaveAs接口将文档保存为PDF
workbookApi.putWorkbookSaveAs(name, outputFilePath, format, options, password, storage, inputFolder);
}
}
示例文档:
PDF效果图: