赞
踩
- import com.aspose.cells.Workbook;
- import com.aspose.cells.PdfSaveOptions;
-
-
- /**
- excelFileDir:excel文件路径
- pdfFilePath:excel文件名称
- */
-
- public String convertExcelToPdf(String excelFileDir ,String pdfFilePath) throws Exception {
- // String pdfFileName = "";//声明pdf文件名称
- FileOutputStream fileOutputStream = null;
- try {
- if (new File(excelFileDir).exists()) {
- // xls转pdf
- Workbook workbook = new Workbook(excelFileDir);
- File pdfFile = new File(pdfFilePath);
- PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
- pdfSaveOptions.setOnePagePerSheet(true);
- fileOutputStream = new FileOutputStream(pdfFile);
- workbook.save(fileOutputStream, SaveFormat.PDF);
- } else {
- return pdfFilePath;
- }
- } catch (Exception e) {
- // logger.error(e.getMessage());
- }finally {
- fileOutputStream.close();
- }
- return pdfFilePath;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。