1.null
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.14</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.14</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency>
2.null
1 import java.awt.Color; 2 import java.awt.Dimension; 3 import java.awt.Rectangle; 4 import java.awt.geom.Rectangle2D; 5 import java.util.List; 6 7 import org.apache.poi.sl.usermodel.VerticalAlignment; 8 import org.apache.poi.sl.usermodel.TableCell.BorderEdge; 9 import org.apache.poi.xslf.usermodel.XMLSlideShow; 10 import org.apache.poi.xslf.usermodel.XSLFSlide; 11 import org.apache.poi.xslf.usermodel.XSLFTable; 12 import org.apache.poi.xslf.usermodel.XSLFTableCell; 13 import org.apache.poi.xslf.usermodel.XSLFTableRow; 14 import org.apache.poi.xslf.usermodel.XSLFTextBox; 15 import org.apache.poi.xslf.usermodel.XSLFTextRun; 16 17 public class PPTUtil { 18 19 public static XMLSlideShow exportPPT() { 20 XMLSlideShow ppt = new XMLSlideShow(); 21 ppt.setPageSize(new Dimension(960, 540)); 22 Dimension dimension = ppt.getPageSize(); 23 System.out.println(dimension.getWidth()+","+dimension.getHeight()); 24 XSLFSlide slide = ppt.createSlide();//创建幻灯片 25 XSLFTextBox textBox = slide.createTextBox(); 26 textBox.setAnchor(new Rectangle(10,10, 400, 40)); 27 XSLFTextRun textRun = textBox.setText("异常报告 –顺丰支付平台异常"); 28 textRun.setFontSize(24.0); 29 textRun.setFontFamily("微软雅黑"); 30 textRun.setBold(true); 31 textRun.setFontColor(Color.BLUE); 32 33 String[] firstRow = {"基本信息","异常时段","异常时长","异常发现时长","优先级","是否故障","异常原因","责任处室"}; 34 String[] secondRow = {"","2018年08月15日 16:50-17:39","49m","0m","A","否","软件-性能不足","企内研发中心-财务管理系统研发部"}; 35 String[] thirdRow = {"故障影响","影响范围:全网影响内容:无实际业务影响,快递员无法立即查看微信支付结果,但可通过客户微信支付结果查看。故障现象:散单微信支付正常,但支付结果状态返回巴枪缓慢。","","","","","",""}; 36 String[] fourthRow = {"过程回顾","开始时间","结束时间","处理室","处理人","处理过程描述(变更、决策相关信息)","",""}; 37 String[] penultimateRow = {"原因检讨过程检讨","原因检讨:8月15日16:40-16:50(异常发生前10分钟),巴枪支付交易明细查询次数206次,与昨天同一时段查询次数73次相比,上涨近3倍,由于支付交易明细查询SQL效率不高,慢SQL在数据库大批量执行全分片扫描,导致数据库性能下降,造成支付结果状态返回巴枪缓慢。过程检讨:定位慢SQL对应的功能模块耗时较长","","","","","",""}; 38 String[] lastRow = {"改进措施","1、切换巴枪支付查询通道从MYCAT到HBASE -----IT服务中心/林文海 2018-8-15 【已完成】2、优化支付交易明细查询功能 -----企内研发中心/夏佳2018-8-23 【计划中】3、支付状态返回巴枪和状态落地功能拆分 -----企内研发中心/ 夏佳 2018-8-31 【计划中】","","","","","",""}; 39 XSLFTable table1 = slide.createTable();//创建表格 40 table1.setAnchor(new Rectangle2D.Double(10, 50,960, 400)); 41 42 XSLFTableRow tableRow1 = table1.addRow(); //创建表格行 43 for(int j = 0; j < 8; j++) { 44 XSLFTableCell tableCell = tableRow1.addCell();//创建表格单元格 45 /*XSLFTextParagraph p = tableCell.addNewTextParagraph(); 46 XSLFTextRun tr = p.addNewTextRun(); 47 tr.setText(String.valueOf(firstRow[j]));*/ 48 tableCell.clearText(); 49 XSLFTextRun tr = tableCell.setText(firstRow[j]); 50 tr.setFontSize(12.0); 51 tr.setFontFamily("微软雅黑"); 52 tr.setBold(true); 53 tableCell.setFillColor(Color.getColor("0xdd7e6b")); 54 //p.setTextAlign(TextAlign.CENTER); 55 tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); 56 57 tableCell.setBorderColor(BorderEdge.left, Color.BLACK); 58 tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK); 59 tableCell.setBorderColor(BorderEdge.right, Color.BLACK); 60 tableCell.setBorderColor(BorderEdge.top, Color.BLACK); 61 } 62 tableRow1.setHeight(20); 63 64 XSLFTableRow tableRow2 = table1.addRow(); //创建表格行 65 for(int j = 0; j < 8; j++) { 66 XSLFTableCell tableCell = tableRow2.addCell();//创建表格单元格 67 /*XSLFTextParagraph p = tableCell.addNewTextParagraph(); 68 XSLFTextRun tr = p.addNewTextRun(); 69 tr.setText(String.valueOf(firstRow[j]));*/ 70 tableCell.clearText(); 71 XSLFTextRun tr = tableCell.setText(secondRow[j]); 72 tr.setFontSize(12.0); 73 tr.setFontFamily("微软雅黑"); 74 //tr.setBold(true); 75 tableCell.setFillColor(Color.getColor("0xdd7e6b")); 76 //p.setTextAlign(TextAlign.CENTER); 77 tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); 78 79 tableCell.setBorderColor(BorderEdge.left, Color.BLACK); 80 tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK); 81 tableCell.setBorderColor(BorderEdge.right, Color.BLACK); 82 tableCell.setBorderColor(BorderEdge.top, Color.BLACK); 83 } 84 tableRow2.setHeight(50); 85 86 XSLFTableRow tableRow3 = table1.addRow(); //创建表格行 87 for(int j = 0; j < 8; j++) { 88 XSLFTableCell tableCell = tableRow3.addCell(); 89 tableCell.clearText(); 90 XSLFTextRun tr = tableCell.setText(thirdRow[j]); 91 tr.setFontSize(12.0); 92 tr.setFontFamily("微软雅黑"); 93 //tr.setBold(true); 94 tableCell.setFillColor(Color.getColor("0xdd7e6b")); 95 //p.setTextAlign(TextAlign.CENTER); 96 tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); 97 98 tableCell.setBorderColor(BorderEdge.left, Color.BLACK); 99 tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK); 100 tableCell.setBorderColor(BorderEdge.right, Color.BLACK); 101 tableCell.setBorderColor(BorderEdge.top, Color.BLACK); 102 } 103 tableRow3.setHeight(50); 104 105 XSLFTableRow tableRow4 = table1.addRow(); //创建表格行 106 for(int j = 0; j < 8; j++) { 107 XSLFTableCell tableCell = tableRow4.addCell();//创建表格单元格 108 /*XSLFTextParagraph p = tableCell.addNewTextParagraph(); 109 XSLFTextRun tr = p.addNewTextRun(); 110 tr.setText(String.valueOf(firstRow[j]));*/ 111 tableCell.clearText(); 112 XSLFTextRun tr = tableCell.setText(fourthRow[j]); 113 tr.setFontSize(12.0); 114 tr.setFontFamily("微软雅黑"); 115 //tr.setBold(true); 116 tableCell.setFillColor(Color.getColor("0xdd7e6b")); 117 //p.setTextAlign(TextAlign.CENTER); 118 tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); 119 120 tableCell.setBorderColor(BorderEdge.left, Color.BLACK); 121 tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK); 122 tableCell.setBorderColor(BorderEdge.right, Color.BLACK); 123 tableCell.setBorderColor(BorderEdge.top, Color.BLACK); 124 } 125 tableRow4.setHeight(50); 126 127 XSLFTableRow tableRow5 = table1.addRow(); //创建表格行 128 for(int j = 0; j < 8; j++) { 129 XSLFTableCell tableCell = tableRow5.addCell();//创建表格单元格 130 /*XSLFTextParagraph p = tableCell.addNewTextParagraph(); 131 XSLFTextRun tr = p.addNewTextRun(); 132 tr.setText(String.valueOf(firstRow[j]));*/ 133 tableCell.clearText(); 134 XSLFTextRun tr = tableCell.setText(penultimateRow[j]); 135 tr.setFontSize(12.0); 136 tr.setFontFamily("微软雅黑"); 137 //tr.setBold(true); 138 tableCell.setFillColor(Color.getColor("0xdd7e6b")); 139 //p.setTextAlign(TextAlign.CENTER); 140 tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); 141 142 tableCell.setBorderColor(BorderEdge.left, Color.BLACK); 143 tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK); 144 tableCell.setBorderColor(BorderEdge.right, Color.BLACK); 145 tableCell.setBorderColor(BorderEdge.top, Color.BLACK); 146 } 147 tableRow5.setHeight(50); 148 149 XSLFTableRow tableRow6 = table1.addRow(); //创建表格行 150 for(int j = 0; j < 8; j++) { 151 XSLFTableCell tableCell = tableRow6.addCell();//创建表格单元格 152 /*XSLFTextParagraph p = tableCell.addNewTextParagraph(); 153 XSLFTextRun tr = p.addNewTextRun(); 154 tr.setText(String.valueOf(firstRow[j]));*/ 155 tableCell.clearText(); 156 XSLFTextRun tr = tableCell.setText(lastRow[j]); 157 tr.setFontSize(12.0); 158 tr.setFontFamily("微软雅黑"); 159 //tr.setBold(true); 160 tableCell.setFillColor(Color.getColor("0xdd7e6b")); 161 //p.setTextAlign(TextAlign.CENTER); 162 tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); 163 164 tableCell.setBorderColor(BorderEdge.left, Color.BLACK); 165 tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK); 166 tableCell.setBorderColor(BorderEdge.right, Color.BLACK); 167 tableCell.setBorderColor(BorderEdge.top, Color.BLACK); 168 } 169 tableRow6.setHeight(50); 170 //设置列宽 171 table1.setColumnWidth(0, 70); 172 table1.setColumnWidth(1, 120); 173 table1.setColumnWidth(2, 120); 174 table1.setColumnWidth(3, 120); 175 table1.setColumnWidth(4, 120); 176 table1.setColumnWidth(5, 120); 177 table1.setColumnWidth(6, 120); 178 table1.setColumnWidth(7, 150); 179 //合并单元格 180 table1.mergeCells(0, 1, 0, 0); 181 table1.mergeCells(2, 2, 1, 7); 182 table1.mergeCells(3, 3, 5, 7); 183 table1.mergeCells(4, 4, 1, 7); 184 table1.mergeCells(5, 5, 1, 7); 185 186 return ppt; 187 } 188 }
3.null
1 @RequestMapping({ "incidentReportExport.do" }) 2 public ResponseEntity<byte[]> incidentReportExport(Long id, HttpServletRequest request, HttpServletResponse response) { 3 4 try { 5 XMLSlideShow ppt = PPTUtil.exportPPT(id); 6 7 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); 8 String filename = "["+id+"]"+sdf.format(new Date())+".pptx"; 9 //String filePath = "/nfsc/ITIL_ITSM/review/" + filename; 10 // String filePath = "D:"+File.separator + filename; 11 // FileOutputStream fos = new FileOutputStream(filePath); 12 // ppt.write(fos); 13 // File file = new File(filePath);//新建一个文件 14 // byte[] b = FileUtils.readFileToByteArray(file); 15 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 16 ppt.write(byteArrayOutputStream); 17 byte[] b = byteArrayOutputStream.toByteArray(); 18 HttpHeaders headers = new HttpHeaders();//http头信息 19 String downloadFileName = new String(filename.getBytes("UTF-8"),"iso-8859-1");//设置编码 20 headers.setContentDispositionFormData("attachment", downloadFileName); 21 headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); 22 //MediaType:互联网媒介类型 contentType:具体请求中的媒体类型信息 23 return new ResponseEntity<byte[]>(b,headers,HttpStatus.CREATED); 24 25 } catch (IOException e) { 26 e.printStackTrace(); 27 logger.error(e.getMessage()); 28 } 29 30 return null; 31 }