zoukankan      html  css  js  c++  java
  • java excel转pdf 工具类

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.aspose.cells.License;
    import com.aspose.cells.Workbook;
    import com.aspose.cells.SaveFormat;
    
    
    
    public class PdfUtilExcel {
        /**
         * EXCEL 转  PDF
         * 
         * @param filepath
         */
        public void excelOfPdf(String filepath,HttpServletRequest request) {
            boolean result = false;
            try {
                InputStream license = PdfUtil.class.getClassLoader().getResourceAsStream("license.xml");
                License aposeLic = new License();
                aposeLic.setLicense(license);
                result = true;
                if (result == true) {
                    Workbook wb = new Workbook(request.getSession().getServletContext().getRealPath("\" +filepath));//原始excel路径
                    String fles = filepath.substring(0, filepath.lastIndexOf("."));
                    File file = new File(request.getSession().getServletContext()
                            .getRealPath("\" +fles+".pdf"));// 输出路径
                    FileOutputStream fileOS = new FileOutputStream(file);
                    wb.save(fileOS, SaveFormat.PDF);
                    fileOS.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
    }
    使用方法:

    PdfUtilExcel excel = new PdfUtilExcel();
    excel.excelOfPdf(filePaths, request);//filePaths为存储地址

     
  • 相关阅读:
    426 根据gop 讲解x264整个过程
    426 x264全局 完整有些东西还没理解
    SAD SATD转过来的
    帧内预测1
    4.1总结
    426 大话dct
    426 pixel赋值问题 mbcmp函数 宏定义
    426 pts dts
    每天进步一点点IAR for ARM_V6.30.1
    每天进步一点点NIOS II按键中断程序
  • 原文地址:https://www.cnblogs.com/sky-zky/p/9639222.html
Copyright © 2011-2022 走看看