jiangping
2024-03-05 b6d2a806e6572ffc4c226c91f0a60b31a7b1fbc0
server/service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java
@@ -21,6 +21,7 @@
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
@@ -885,10 +886,12 @@
            sxssfWorkbook.write(out);
            byte [] bookByteAry = out.toByteArray();
            InputStream     in = new ByteArrayInputStream(bookByteAry);
            String tempExcel = saveIsToFile(in);
            String tempPdf =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".pdf";
            ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF
//            ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF
            ExcelToPdfTool.excelToPdf(tempExcel,tempPdf);//转PDF
            File f = new File(tempPdf);
            if(f!=null && f.isFile()){
            if(f!=null && f.isFile() && f.length()>0){
                return tempPdf;
            }
        } catch (Exception e) {
@@ -1108,10 +1111,12 @@
            sxssfWorkbook.write(out);
            byte [] bookByteAry = out.toByteArray();
            InputStream     in = new ByteArrayInputStream(bookByteAry);
            String tempExcel = saveIsToFile(in);
            String tempPdf =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".pdf";
            ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF
//            ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF
            ExcelToPdfTool.excelToPdf(tempExcel,tempPdf);//转PDF
            File f = new File(tempPdf);
            if(f!=null && f.isFile()){
            if(f!=null && f.isFile() && f.length()>0){
                return tempPdf;
            }
        } catch (Exception e) {
@@ -1120,6 +1125,27 @@
        return null;
    }
    private String saveIsToFile(InputStream inputStream) {
            try {
                String fileName =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".xlsx";
                File file = new File(fileName); // 指定保存到本地的文件名及路径
                file.createNewFile();
                OutputStream outputStream = new FileOutputStream(file);
                byte[] buffer = new byte[1024];
                int bytesRead;
                while ((bytesRead = inputStream.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, bytesRead);
                }
                outputStream.close();
                inputStream.close();
                return fileName;
            }catch (Exception e){
            }
            return null;
    }
    @Data
    @AllArgsConstructor