spire.cloud.excel sdk java提供generalapi接口和workbookapi接口,支持将本地excel工作簿和云端excel文档转换为ods, pdf, xps, pcl, ps等格式。本文将介绍如何分别调用generalapi接口和workbookapi接口将excel 文档保存为pdf格式。
首先,请通过 。其次,需要在冰蓝云凯发线上登陆下载网址官网 () 注册账号,创建我的应用程序,获得 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效果图: