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

POI导出PPT的更多相关文章

  1. 关于java使用POI导出ppt ,其中表格setText 失败问题

    1.导出ppt 必要的包 使用maven <dependency> <groupId>org.apache.poi</groupId> <artifactId ...

  2. poi导出excel

    Java使用poi组件导出excel报表,能导出excel报表的还可以使用jxl组件,但jxl想对于poi功能有限,jxl应该不能载excel插入浮动层图片,poi能很好的实现输出excel各种功能, ...

  3. java poi 操作ppt

    java poi 操作ppt 可以参考: https://www.w3cschool.cn/apache_poi_ppt/apache_poi_ppt_installation.html http:/ ...

  4. java使用poi读取ppt文件和poi读取excel、word示例

    java使用poi读取ppt文件和poi读取excel.word示例 http://www.jb51.net/article/48092.htm

  5. POI导出excel的简单demo

    目前使用过两种导出excel的方式,一种是如题所示的使用POI的方式进行数据的导出,这种方式一般只有在处理比较多的数据或者说需要导出的excel表格中有图片之类的需要特殊处理的文件的时候使用:还有一种 ...

  6. [转载]poi导出excel,可以自定义保存路径

    poi导出excel比js导出excel安全性更好,在使用poi导出excel时,先要导入poi-3.5-FINAL-20090928.jar包到你项目的lib目录下,我这里选择是3.5版的 1.ac ...

  7. POI导出EXCEL经典实现

    1.Apache POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程式对Microsoft Office格式档案读和写的功能. .NET的开发人员则 ...

  8. Java POI 导出EXCEL经典实现 Java导出Excel

    转自http://blog.csdn.net/evangel_z/article/details/7332535 在web开发中,有一个经典的功能,就是数据的导入导出.特别是数据的导出,在生产管理或者 ...

  9. poi导出word

    最近做了个poi导出word的功能 下面是代码: 一个可以参考的例子: package com.lzb.crm.web; import java.io.FileOutputStream; import ...

随机推荐

  1. 20200221--python学习第14天

    今日内容 带参数的装饰器:flash框架+django缓存+写装饰器实现被装饰的函数要执行N次 模块: os sys time datetime和timezone[了解] 内容回顾与补充 1.函数 写 ...

  2. coat 彩色的cat

    # 和cat类似,但每一行一种颜色,方便查看 curl -o coat https://raw.githubusercontent.com/oldratlee/useful-scripts/maste ...

  3. php 安装扩展插件实例-gd库

    今天给php 安装一个扩展插件 gd库   一.gd库是什么 gd库是一个开源的图像处理库,它通过提供一系列用来处理图片的API,使其可以用来创建图表.图形.缩略图以及其他图像的处理操作. gd库支持 ...

  4. (数据科学学习手札78)基于geopandas的空间数据分析——基础可视化

    本文对应代码和数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 通过前面的文章,我们已经对geopanda ...

  5. for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法

    一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addT ...

  6. Blazor client-side + webapi (.net core 3.1) 添加jwt验证流程(非host)第一步

    第一步,设置并检查CROS跨域请求 因为我们并不打算将Blazor 由webapi来进行host,所以Blazor和api将是两个域名,这样操作即方便以后单独使用Blazor来写前端,但后端采用已有或 ...

  7. JAVA 线程池原理

    如果并发的请求数量非常多,但每个线程执行的时间很短,这样就会频繁的创建和销毁线程,如此一来会大大降低系统的效率.这就是线程池的目的了.线程池为线程生命周期的开销和资源不足问题提供了解决方案.通过对多个 ...

  8. 在阿里云服务器上安装mysql及重置密码

    参考链接:https://www.cnblogs.com/ljysy/p/10324854.html 下载与安装MySQL: 这里采用Yum管理好了各种rpm包的依赖,能够从指定的服务器自动下载RPM ...

  9. PHP0017:PHP http协议 视频下载

  10. 基于element-ui 模仿微信聊天页面以及滚动条隐藏在chrome和其他浏览器的处理

    1.效果图 2.代码 <template> <div style=" overflow: hidden;"> <el-row> <el-c ...