| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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) { |
| | |
| | | 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 |