首页>代码>java转换excel为pdf文件>/AsposeCells/src/com/demo/Test.java
01package com.demo;
02 
03import java.io.File;
04import java.io.FileOutputStream;
05import java.io.InputStream;
06 
07import com.aspose.cells.License;
08import com.aspose.cells.SaveFormat;
09import com.aspose.cells.Workbook;
10 
11/**
12 *
13 * 由于ASPOSE比较吃内存,操作大一点的文件就会堆溢出,所以请先设置好java虚拟机参数:-Xms512m -Xmx512m(参考值)<br>
14 * 如有疑问,请在CSDN下载界面留言,或者联系QQ569925980<br>
15 *
16 * @author Spark
17 *
18 */
19public class Test {
20    /*Aspose.Words license
22 
24 
26 
28 
30        */
31    /**
32     * 获取license
33     *
34     * @return
35     */
36    public static boolean getLicense() {
37        boolean result = false;
38        try {
39            InputStream is = Test.class.getClassLoader().getResourceAsStream("\\license.xml");
40            License aposeLic = new License();
41            aposeLic.setLicense(is);
42            result = true;
43        } catch (Exception e) {
44            e.printStackTrace();
45        }
46        return result;
47    }
48 
49    /**
50     * 支持DOC, DOCX, OOXML, RTF, HTML, OpenDocument, PDF, EPUB, XPS, SWF等相互转换<br>
51     *
52     * @param args
53     */
54    public static void main(String[] args) {
55        // 验证License
56        if (!getLicense()) {
57            return;
58        }
59 
60        try {
61            long old = System.currentTimeMillis();
62            String sourceFilePath="L:/testPDF/test.xls";//可生成PDF 没问题
63             
64            Workbook wb = new Workbook(sourceFilePath);// 原始excel路径
65            File pdfFile = new File("L:\\testPDF\\PDF\\test.pdf");// 输出路径
66            FileOutputStream fileOS = new FileOutputStream(pdfFile);
67 
68            wb.save(fileOS, SaveFormat.PDF);
69 
70            long now = System.currentTimeMillis();
71            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");
72        } catch (Exception e) {
73            e.printStackTrace();
74        }
75    }
76}
最近下载更多
微信网友_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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友