zoukankan      html  css  js  c++  java
  • 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应放在..WebRootWEB-INFclasses路径下
    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文档

  • 相关阅读:
    一个简单的空间配置器
    【转】c++中placement new操作符
    类的operator new与operator delete的重载【转】
    STL中常用的c++语法
    java编程思想-多态
    java编程思想-复用类(2)
    java编程思想-复用类
    import与require的区别
    gulp插件
    gulp-gulpfile.js语法说明
  • 原文地址:https://www.cnblogs.com/qiwu1314/p/6121696.html
Copyright © 2011-2022 走看看