java利用Aspose.cells.jar將本地excel文檔轉化成pdf(完美破解版 無水印 無中文亂碼)


下載aspose-cells-8.5.2.jar包 http://pan.baidu.com/s/1kUBzsQ7

JAVA代碼

 1 package webViewer;
 2 
 3 import java.io.*;  
 4 import com.aspose.cells.*;      //引入aspose-cells-8.5.2.jar包
 5 
 6 public class Excel2Pdf {
 7 
 8     public static boolean getLicense() {
 9         boolean result = false;
10         try {
11             InputStream is = Test.class.getClassLoader().getResourceAsStream("xlsxlicense.xml"); //  license.xml應放在..\WebRoot\WEB-INF\classes路徑下
12             License aposeLic = new License();
13             aposeLic.setLicense(is);
14             result = true;
15         } catch (Exception e) {               
16             e.printStackTrace();
17         }
18         return result;
19     }
20     
21     public static void excel2pdf(String Address) {
22         
23         if (!getLicense()) {          // 驗證License 若不驗證則轉化出的pdf文檔會有水印產生
24             return;
25         }
26         try {
27             File pdfFile = new File("C:/Program Files (x86)/Apache Software Foundation/Tomcat 7.0/webapps/generic/web/file/pdf1.pdf");// 輸出路徑
28             Workbook wb = new Workbook(Address);// 原始excel路徑            
29             FileOutputStream fileOS = new FileOutputStream(pdfFile);
30             wb.save(fileOS, SaveFormat.PDF);  
31             fileOS.close();          
32         } catch (Exception e) {
33             e.printStackTrace();
34         }
35     }
36 }

調用代碼

1 package webViewer;
2 
3 public class Test {
4     public static void main(String[] args){
5 Excel2Pdf.excel2pdf("C:/Program Files (x86)/Apache Software Foundation/Tomcat 7.0/webapps/generic/web/file/5.xlsx");
6 }
7 }

生成pdf文檔


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM