首页>代码>java转换excel为pdf文件>/AsposeCells/src/com/demo/Excel2Pdf.java
package com.demo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import com.aspose.cells.License; //引入aspose-cells-8.5.2.jar包
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;

/**
 * @version 1.0 说明 :
 */
public class Excel2Pdf {

	public static void main(String[] args) {

		String sourceFilePath="L:/testPDF/test.xls";//可生成PDF 没问题
		String desFilePath="L:\\testPDF\\PDF\\test.pdf";

		excel2pdf(sourceFilePath, desFilePath);

	}

	public static boolean getLicense() {
		boolean result = false;
		try {
			InputStream is = Word2Pdf.class.getClassLoader()
					.getResourceAsStream("\\license.xml");
			License aposeLic = new License();
			aposeLic.setLicense(is);
			result = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static void excel2pdf(String sourceFilePath, String desFilePath) {
		if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
			return;
		}
		try {
			File pdfFile = new File(desFilePath);// 输出路径
			Workbook wb = new Workbook(sourceFilePath);// 原始excel路径
			FileOutputStream fileOS = new FileOutputStream(pdfFile);
			wb.save(fileOS, SaveFormat.PDF);
			fileOS.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
最近下载更多
微信网友_7204178979377152  LV1 2024年10月11日
13043860zj  LV16 2023年10月31日
ewan007  LV30 2023年6月19日
G你太美  LV9 2022年10月13日
8战魂5无双8  LV43 2022年9月13日
bnahlz  LV1 2022年3月2日
『周先生。』  LV1 2021年11月4日
Neoest  LV2 2021年7月15日
XuHuaHao  LV3 2021年6月28日
yinyuke  LV1 2021年6月15日
最近浏览更多
Jacko01  LV8 3月20日
3993zby  LV2 2024年11月11日
微信网友_7204178979377152  LV1 2024年10月10日
wsaffsa  LV2 2024年2月19日
NHealers  LV5 2023年12月14日
13043860zj  LV16 2023年10月31日
chen影 2023年10月31日
暂无贡献等级
ewan007  LV30 2023年6月19日
zj0010722  LV2 2023年3月2日
ssy552  LV10 2023年2月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友