package com.hys.home.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import com.aspose.cells.License;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
/**
*
* @ClassName: ExcelToPdf
* @Description: TODO(这里用一句话描述这个类的作用)
* @author zouyuanchao
* @date 2017-5-26
*
*/
public class ExcelToPdf {
/**
* 获取license
*
* @return
*/
public static boolean getLicense() {
boolean result = false;
try {
InputStream is = ExcelToPdf.class.getClassLoader().getResourceAsStream("config/license.xml");
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static int excelTopdf(String excelPath){
System.out.println("excel开始转换pdf========>>");
int result = 0;
// 验证License
if (!getLicense()) {
return 0;
}
try {
long old = System.currentTimeMillis();
Workbook wb = new Workbook(excelPath);// 原始excel路径
String pdfPath = excelPath.substring(0,excelPath.indexOf("."))+".pdf";
File pdfFile = new File(pdfPath);// 输出路径
FileOutputStream fileOS = new FileOutputStream(pdfFile);
wb.save(fileOS, SaveFormat.PDF);
long now = System.currentTimeMillis();
result=1;
System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
excelTopdf("d:/doc/abcdefg.doc");
}
}
excel转pdf
最新推荐文章于 2022-03-29 13:57:08 发布