| | |
| | | package com.zy.crm.manager.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.documents4j.api.DocumentType; |
| | | import com.documents4j.api.IConverter; |
| | | import com.documents4j.job.LocalConverter; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.apache.xmlbeans.XmlCursor; |
| | | import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; |
| | |
| | | import java.io.*; |
| | | import java.text.DecimalFormat; |
| | | import java.text.NumberFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | return ResponseEntity.ok() |
| | | .headers(headers) |
| | | .body(resource); |
| | | } |
| | | |
| | | /* |
| | | * word转PDF |
| | | * */ |
| | | public static void documents4jWordToPdf(String sourcePath, String targetPath) { |
| | | File inputWord = new File(sourcePath); |
| | | File outputFile = new File(targetPath); |
| | | try { |
| | | InputStream docxInputStream = new FileInputStream(inputWord); |
| | | OutputStream outputStream = new FileOutputStream(outputFile); |
| | | IConverter converter = LocalConverter.builder().build(); |
| | | boolean execute = converter.convert(docxInputStream) |
| | | .as(DocumentType.DOCX) |
| | | .to(outputStream) |
| | | .as(DocumentType.PDF).schedule().get(); |
| | | outputStream.close(); |
| | | docxInputStream.close(); |
| | | |
| | | System.out.println("转换完毕 targetPath = "+outputFile.getAbsolutePath()); |
| | | converter.shutDown(); |
| | | return; |
| | | } catch (Exception e) { |
| | | System.out.println("[documents4J] word转pdf失败:"+e.toString()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | public static String formatNumberForAccounting(double number) { |
| | | if (number == 0) { |
| | | return "0.00"; |
| | | } |
| | | NumberFormat formatter = new DecimalFormat("#,###.00"); |
| | | return formatter.format(number); |
| | | } |