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

 import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.List; import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.sl.usermodel.TableCell.BorderEdge;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFTable;
import org.apache.poi.xslf.usermodel.XSLFTableCell;
import org.apache.poi.xslf.usermodel.XSLFTableRow;
import org.apache.poi.xslf.usermodel.XSLFTextBox;
import org.apache.poi.xslf.usermodel.XSLFTextRun; public class PPTUtil { public static XMLSlideShow exportPPT() {
XMLSlideShow ppt = new XMLSlideShow();
ppt.setPageSize(new Dimension(960, 540));
Dimension dimension = ppt.getPageSize();
System.out.println(dimension.getWidth()+","+dimension.getHeight());
XSLFSlide slide = ppt.createSlide();//创建幻灯片
XSLFTextBox textBox = slide.createTextBox();
textBox.setAnchor(new Rectangle(10,10, 400, 40));
XSLFTextRun textRun = textBox.setText("异常报告 –顺丰支付平台异常");
textRun.setFontSize(24.0);
textRun.setFontFamily("微软雅黑");
textRun.setBold(true);
textRun.setFontColor(Color.BLUE); String[] firstRow = {"基本信息","异常时段","异常时长","异常发现时长","优先级","是否故障","异常原因","责任处室"};
String[] secondRow = {"","2018年08月15日 16:50-17:39","49m","0m","A","否","软件-性能不足","企内研发中心-财务管理系统研发部"};
String[] thirdRow = {"故障影响","影响范围:全网影响内容:无实际业务影响,快递员无法立即查看微信支付结果,但可通过客户微信支付结果查看。故障现象:散单微信支付正常,但支付结果状态返回巴枪缓慢。","","","","","",""};
String[] fourthRow = {"过程回顾","开始时间","结束时间","处理室","处理人","处理过程描述(变更、决策相关信息)","",""};
String[] penultimateRow = {"原因检讨过程检讨","原因检讨:8月15日16:40-16:50(异常发生前10分钟),巴枪支付交易明细查询次数206次,与昨天同一时段查询次数73次相比,上涨近3倍,由于支付交易明细查询SQL效率不高,慢SQL在数据库大批量执行全分片扫描,导致数据库性能下降,造成支付结果状态返回巴枪缓慢。过程检讨:定位慢SQL对应的功能模块耗时较长","","","","","",""};
String[] lastRow = {"改进措施","1、切换巴枪支付查询通道从MYCAT到HBASE -----IT服务中心/林文海 2018-8-15 【已完成】2、优化支付交易明细查询功能 -----企内研发中心/夏佳2018-8-23 【计划中】3、支付状态返回巴枪和状态落地功能拆分 -----企内研发中心/ 夏佳 2018-8-31 【计划中】","","","","","",""};
XSLFTable table1 = slide.createTable();//创建表格
table1.setAnchor(new Rectangle2D.Double(10, 50,960, 400)); XSLFTableRow tableRow1 = table1.addRow(); //创建表格行
for(int j = 0; j < 8; j++) {
XSLFTableCell tableCell = tableRow1.addCell();//创建表格单元格
/*XSLFTextParagraph p = tableCell.addNewTextParagraph();
XSLFTextRun tr = p.addNewTextRun();
tr.setText(String.valueOf(firstRow[j]));*/
tableCell.clearText();
XSLFTextRun tr = tableCell.setText(firstRow[j]);
tr.setFontSize(12.0);
tr.setFontFamily("微软雅黑");
tr.setBold(true);
tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//p.setTextAlign(TextAlign.CENTER);
tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); tableCell.setBorderColor(BorderEdge.left, Color.BLACK);
tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK);
tableCell.setBorderColor(BorderEdge.right, Color.BLACK);
tableCell.setBorderColor(BorderEdge.top, Color.BLACK);
}
tableRow1.setHeight(20); XSLFTableRow tableRow2 = table1.addRow(); //创建表格行
for(int j = 0; j < 8; j++) {
XSLFTableCell tableCell = tableRow2.addCell();//创建表格单元格
/*XSLFTextParagraph p = tableCell.addNewTextParagraph();
XSLFTextRun tr = p.addNewTextRun();
tr.setText(String.valueOf(firstRow[j]));*/
tableCell.clearText();
XSLFTextRun tr = tableCell.setText(secondRow[j]);
tr.setFontSize(12.0);
tr.setFontFamily("微软雅黑");
//tr.setBold(true);
tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//p.setTextAlign(TextAlign.CENTER);
tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); tableCell.setBorderColor(BorderEdge.left, Color.BLACK);
tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK);
tableCell.setBorderColor(BorderEdge.right, Color.BLACK);
tableCell.setBorderColor(BorderEdge.top, Color.BLACK);
}
tableRow2.setHeight(50); XSLFTableRow tableRow3 = table1.addRow(); //创建表格行
for(int j = 0; j < 8; j++) {
XSLFTableCell tableCell = tableRow3.addCell();
tableCell.clearText();
XSLFTextRun tr = tableCell.setText(thirdRow[j]);
tr.setFontSize(12.0);
tr.setFontFamily("微软雅黑");
//tr.setBold(true);
tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//p.setTextAlign(TextAlign.CENTER);
tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); tableCell.setBorderColor(BorderEdge.left, Color.BLACK);
tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK);
tableCell.setBorderColor(BorderEdge.right, Color.BLACK);
tableCell.setBorderColor(BorderEdge.top, Color.BLACK);
}
tableRow3.setHeight(50); XSLFTableRow tableRow4 = table1.addRow(); //创建表格行
for(int j = 0; j < 8; j++) {
XSLFTableCell tableCell = tableRow4.addCell();//创建表格单元格
/*XSLFTextParagraph p = tableCell.addNewTextParagraph();
XSLFTextRun tr = p.addNewTextRun();
tr.setText(String.valueOf(firstRow[j]));*/
tableCell.clearText();
XSLFTextRun tr = tableCell.setText(fourthRow[j]);
tr.setFontSize(12.0);
tr.setFontFamily("微软雅黑");
//tr.setBold(true);
tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//p.setTextAlign(TextAlign.CENTER);
tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); tableCell.setBorderColor(BorderEdge.left, Color.BLACK);
tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK);
tableCell.setBorderColor(BorderEdge.right, Color.BLACK);
tableCell.setBorderColor(BorderEdge.top, Color.BLACK);
}
tableRow4.setHeight(50); XSLFTableRow tableRow5 = table1.addRow(); //创建表格行
for(int j = 0; j < 8; j++) {
XSLFTableCell tableCell = tableRow5.addCell();//创建表格单元格
/*XSLFTextParagraph p = tableCell.addNewTextParagraph();
XSLFTextRun tr = p.addNewTextRun();
tr.setText(String.valueOf(firstRow[j]));*/
tableCell.clearText();
XSLFTextRun tr = tableCell.setText(penultimateRow[j]);
tr.setFontSize(12.0);
tr.setFontFamily("微软雅黑");
//tr.setBold(true);
tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//p.setTextAlign(TextAlign.CENTER);
tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); tableCell.setBorderColor(BorderEdge.left, Color.BLACK);
tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK);
tableCell.setBorderColor(BorderEdge.right, Color.BLACK);
tableCell.setBorderColor(BorderEdge.top, Color.BLACK);
}
tableRow5.setHeight(50); XSLFTableRow tableRow6 = table1.addRow(); //创建表格行
for(int j = 0; j < 8; j++) {
XSLFTableCell tableCell = tableRow6.addCell();//创建表格单元格
/*XSLFTextParagraph p = tableCell.addNewTextParagraph();
XSLFTextRun tr = p.addNewTextRun();
tr.setText(String.valueOf(firstRow[j]));*/
tableCell.clearText();
XSLFTextRun tr = tableCell.setText(lastRow[j]);
tr.setFontSize(12.0);
tr.setFontFamily("微软雅黑");
//tr.setBold(true);
tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//p.setTextAlign(TextAlign.CENTER);
tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE); tableCell.setBorderColor(BorderEdge.left, Color.BLACK);
tableCell.setBorderColor(BorderEdge.bottom, Color.BLACK);
tableCell.setBorderColor(BorderEdge.right, Color.BLACK);
tableCell.setBorderColor(BorderEdge.top, Color.BLACK);
}
tableRow6.setHeight(50);
//设置列宽
table1.setColumnWidth(0, 70);
table1.setColumnWidth(1, 120);
table1.setColumnWidth(2, 120);
table1.setColumnWidth(3, 120);
table1.setColumnWidth(4, 120);
table1.setColumnWidth(5, 120);
table1.setColumnWidth(6, 120);
table1.setColumnWidth(7, 150);
//合并单元格
table1.mergeCells(0, 1, 0, 0);
table1.mergeCells(2, 2, 1, 7);
table1.mergeCells(3, 3, 5, 7);
table1.mergeCells(4, 4, 1, 7);
table1.mergeCells(5, 5, 1, 7); return ppt;
}
}

PPTUtil

3.null

 @RequestMapping({ "incidentReportExport.do" })
public ResponseEntity<byte[]> incidentReportExport(Long id, HttpServletRequest request, HttpServletResponse response) { try {
XMLSlideShow ppt = PPTUtil.exportPPT(id); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
String filename = "["+id+"]"+sdf.format(new Date())+".pptx";
//String filePath = "/nfsc/ITIL_ITSM/review/" + filename;
// String filePath = "D:"+File.separator + filename;
// FileOutputStream fos = new FileOutputStream(filePath);
// ppt.write(fos);
// File file = new File(filePath);//新建一个文件
// byte[] b = FileUtils.readFileToByteArray(file);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ppt.write(byteArrayOutputStream);
byte[] b = byteArrayOutputStream.toByteArray();
HttpHeaders headers = new HttpHeaders();//http头信息
String downloadFileName = new String(filename.getBytes("UTF-8"),"iso-8859-1");//设置编码
headers.setContentDispositionFormData("attachment", downloadFileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//MediaType:互联网媒介类型 contentType:具体请求中的媒体类型信息
return new ResponseEntity<byte[]>(b,headers,HttpStatus.CREATED); } catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
} return null;
}

Controller

最新文章

  1. selenium自动化基础知识
  2. [转]CSS hack大全&amp;详解
  3. DNS报文格式
  4. webstorm修改文件,webpack-dev-server不自动编译刷新的解决办法
  5. javascript oo实现(转)
  6. sp.ui.rte.js参数错误
  7. 7 天玩转 ASP.NET MVC - 第 1 天
  8. SSL handshake failed: SSL 错误:在证书中检测到违规的密钥用法。
  9. OC1_类与对象
  10. DownloadManager 下载管理类
  11. Java高级框架------Spring(二)
  12. 如何使用Log4j
  13. 2010 NEERC Western subregional
  14. Office 2010 激活 - Failed to inject memory!
  15. C语言 &#183; 身份证排序
  16. [转载]jsonp详解
  17. TitanX Server安装Caffe
  18. 04_Docker入门(下)之docker镜像和仓库的使用
  19. nopi导出
  20. C语言实例解析精粹学习笔记——31

热门文章

  1. 获取页面form表单对象的方式
  2. mysql8.0编译安装
  3. Vscode使用
  4. ASP.NET MVC通用权限管理系统(响应布局)源码更新介绍
  5. 彻底理解Windows认证1
  6. 《ADCrowdNet》密集人群检测论文笔记
  7. Windows2008R2 一键安全优化脚本
  8. vue基于video.js实现视频播放暂停---切图网
  9. 【python基础语法】第5天作业练习题
  10. python中class的定义及使用