01 | package com.demo; |
02 |
03 | import java.io.File; |
04 | import java.io.FileOutputStream; |
05 | import java.io.InputStream; |
06 |
07 | import com.aspose.cells.License; |
08 | import com.aspose.cells.SaveFormat; |
09 | import com.aspose.cells.Workbook; |
10 |
11 | /** |
12 | * |
13 | * 由于ASPOSE比较吃内存,操作大一点的文件就会堆溢出,所以请先设置好java虚拟机参数:-Xms512m -Xmx512m(参考值)<br> |
14 | * 如有疑问,请在CSDN下载界面留言,或者联系QQ569925980<br> |
15 | * |
16 | * @author Spark |
17 | * |
18 | */ |
19 | public 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 | } |