|
@@ -0,0 +1,89 @@
|
|
|
+package com.zglc.fm.utils;
|
|
|
+
|
|
|
+import com.aspose.cells.*;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class ExcelToPdf {
|
|
|
+
|
|
|
+ public static void loadLicense() {
|
|
|
+ final InputStream is = DocToPdf.class.getClassLoader().getResourceAsStream("license.xml");
|
|
|
+ final License aposeLic = new License();
|
|
|
+ try {
|
|
|
+ aposeLic.setLicense(is);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static File convertExcel2Pdf(final String docPath, final String pdfLocal) {
|
|
|
+ FileUtils.mkDirIfNotExists(new File(pdfLocal));
|
|
|
+ final String nameWithoutExtension = FileUtils.getNameWithoutExtension(docPath);
|
|
|
+ final File docPdfFile = new File(pdfLocal + File.separator + nameWithoutExtension + ".pdf");
|
|
|
+ if (docPdfFile.exists() && docPdfFile.length() != 0L) {
|
|
|
+ return docPdfFile;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ InputStream fileInput = new FileInputStream(docPath);// 待处理的文件
|
|
|
+ Workbook wb = new Workbook(fileInput);
|
|
|
+ FileOutputStream fileOS = new FileOutputStream(docPdfFile.getPath());
|
|
|
+
|
|
|
+ wb.save(fileOS, SaveFormat.PDF);
|
|
|
+ return docPdfFile;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// public String LogExport(List<LogEntity> logs) throws Exception {
|
|
|
+//
|
|
|
+// Workbook workbook = new Workbook();
|
|
|
+// WorksheetCollection worksheets = workbook.getWorksheets();
|
|
|
+// Worksheet worksheet = worksheets.get(0);
|
|
|
+// Cells cells = worksheet.getCells();
|
|
|
+//
|
|
|
+// //设置标题样式
|
|
|
+// Style HeaderStyle = workbook.createStyle();
|
|
|
+// HeaderStyle.getFont().setBold(true); //文字加粗
|
|
|
+// HeaderStyle.setName("宋体"); //文字字体
|
|
|
+// HeaderStyle.getFont().setSize(13); //文字大小
|
|
|
+// HeaderStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
|
|
|
+// HeaderStyle.setTextWrapped(true);//单元格内容自动换行
|
|
|
+//
|
|
|
+// //设置内容样式
|
|
|
+// Style cellsStyle = workbook.createStyle();
|
|
|
+// cellsStyle.setHorizontalAlignment(TextAlignmentType.CENTER); //居中
|
|
|
+// HeaderStyle.setName("宋体"); //文字字体
|
|
|
+// HeaderStyle.getFont().setSize(12); //文字大小
|
|
|
+// cellsStyle.setTextWrapped(true);//单元格内容自动换行
|
|
|
+//
|
|
|
+// for (int i = 0; i < 10; i++) {
|
|
|
+// cells.get(0, i).setValue("标题" + (i+1));
|
|
|
+// cells.get(0, i).setStyle(HeaderStyle);
|
|
|
+// cells.setRowHeight(0,25);
|
|
|
+// cells.setColumnWidth(i,25);
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (int i = 0; i < 10; i++) {
|
|
|
+// cells.get(1, i).setValue("哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈");
|
|
|
+// cells.get(1, i).setStyle(cellsStyle);
|
|
|
+// cells.setRowHeight(i, 20);
|
|
|
+// cells.setColumnWidth(i, 38);
|
|
|
+// }
|
|
|
+//
|
|
|
+// String filename = "xxxxxx.xlsx";
|
|
|
+// try {
|
|
|
+//
|
|
|
+// workbook.save(filename, SaveFormat.XLSX);
|
|
|
+// } catch (Exception ex) {
|
|
|
+// ex.printStackTrace();
|
|
|
+// }
|
|
|
+// return filename;
|
|
|
+// }
|
|
|
+}
|