From 15e225d692605505d549764e2071770e8686f8c3 Mon Sep 17 00:00:00 2001 From: 许鹏程 <1821349743@qq.com> Date: 星期五, 09 六月 2023 18:27:15 +0800 Subject: [PATCH] excel 转pdf --- src/main/java/com/product/file/util/AsposeUtil.java | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/product/file/util/AsposeUtil.java b/src/main/java/com/product/file/util/AsposeUtil.java index 152695e..74e22d9 100644 --- a/src/main/java/com/product/file/util/AsposeUtil.java +++ b/src/main/java/com/product/file/util/AsposeUtil.java @@ -33,11 +33,11 @@ is = AsposeUtil.class.getClassLoader().getResourceAsStream("license.xml"); com.aspose.cells.License excel = new com.aspose.cells.License(); excel.setLicense(is); - + is = AsposeUtil.class.getClassLoader().getResourceAsStream("license.xml"); com.aspose.words.License word = new com.aspose.words.License(); word.setLicense(is); - + is = AsposeUtil.class.getClassLoader().getResourceAsStream("license.xml"); com.aspose.slides.License ppt = new com.aspose.slides.License(); ppt.setLicense(is); @@ -58,7 +58,7 @@ return result; } /** - * + * * @param officePath * @param OutPutPath * @throws BaseException @@ -71,8 +71,11 @@ FileOutputStream fileOS=null; try { File file = new File(OutPutPath); - if (!file.exists()) { - file.mkdirs(); + if(!file.getParentFile().exists()){ + file.getParentFile().mkdirs(); + } + if (!file.isFile()) { + file.createNewFile(); } Workbook wb = new Workbook(officePath);// 鍘熷excel璺緞 File pdfFile = new File(OutPutPath);// 杈撳嚭璺緞 @@ -82,6 +85,7 @@ pdfSaveOptions.setAllColumnsInOnePagePerSheet(true); wb.save(fileOS, pdfSaveOptions); } catch (Exception e) { + e.printStackTrace(); throw new BaseException(e); }finally{ if(fileOS!=null) { @@ -95,7 +99,7 @@ } } /** - * + * * @param officePath * @param OutPutPath * @throws BaseException @@ -129,7 +133,7 @@ } } /** - * + * * @param officePath * @param OutPutPath * @throws BaseException @@ -261,7 +265,7 @@ } return OutPutPath+officeName; } - + public static void main(String args[]) { String file="E:/work/娌勫磧/FE6.6浜у搧鎶ヤ环宸ュ叿-鏂� - 鍓湰.xlsx"; AsposeUtil.OfficeToPdf(file); -- Gitblit v1.9.2