sky-zky
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为存储地址

 

 

分类:

技术点:

相关文章:

  • 2021-10-08
  • 2021-12-29
  • 2021-12-16
  • 2021-11-07
  • 2021-06-26
  • 2022-02-20
  • 2022-12-23
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2021-12-29
  • 2021-12-30
  • 2021-08-06
  • 2021-08-01
  • 2022-12-23
相关资源
相似解决方案