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. VFP 用 SPT 来发布一条 SELECT 到一个新的 SQL Server 表

    为了发布一条 SQL SELECT 语句来创建一个新的 SQL Server 表,  SQL Server 数据库的 select into/bulkcopy 选项必须是可用的. 在默认情况下, 对于 ...

  2. Windows+Python+Selenium基础篇之1-环境搭建

    1.所需工具包1.1Selenium for python1.2  Python  1.3  Notepad++或python IDE 2.  环境搭建2.1  下载和安装Pythonpython2. ...

  3. Nginx Rewrite相关功能

    目录 Nginx Rewrite相关功能 ngx_http_rewrite_module模块指令: if指令: set指令: break指令: return指令: rewrite_log指令: rew ...

  4. 使用vscode对threejs的本地调试

    始终坚信阅读和调试结合的方式,才是学习开源的高效方法 一.老版本调试 遥想当年的threejs(使用版本为r75)还没有CommonJS,对于我这个小白可以拿起大刀大杀四方......(咳.咳. 就是 ...

  5. 关于Redis缓存预热的思考

    系统上线时,提前将相关的缓存数据直接加载到缓存系统.避免在用户请求的时候,先查询数据库,然后再将数据缓存的问题. 这里我考虑2个问题: A.哪些数据需要预热? B.如何预热? 关于问题A,根据不同的业 ...

  6. Leetcode字典树-720:词典中最长的单词

    第一次做leetcode的题目,虽然做的是水题,但是菜鸟太菜,刚刚入门,这里记录一些基本的知识点.大佬看见请直接路过. https://leetcode-cn.com/problems/longest ...

  7. 第一天,初学Markdown

    Markdown学习 二级标题 三级标题 字体 hello,world hello,world hello,world hello,world 引用 飞冲 分割线 图片 超链接 跳转到安徽科技学院 列 ...

  8. 笔记-Git基础

    git配置 git config --global user.name "xxx" //配置用户名 git config --global user.email "xxx ...

  9. Java设计模式之Iterator

    public interface Aggregate { //调用iterator方法生成实现Iterator接口的类的实例 public abstract Iterator iterator(); ...

  10. stream重复Key的处理

    Map<String, List<Model>> modelMap = modelList .stream() .collect(Collectors .toMap(model ...