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. ELF文件之三——使用链接脚本-2个函数

    main.c int main() { ; } int add() { ; } main.o的比较 与之二相比,section header offset由0x90变为0xA4,增加0x14,即add ...

  2. 维基逃离MySQL 力挺开源数据库 MariaDB

    近日全球著名百科类网站维基百科宣布,将不会再用MySQL数据库,据国外媒体报道,很多年,MySQL一直是热门的开源数据库,不过在被甲骨文收购后,面临闭源的风险.因此维基百科将切换到另外一款开源数据库M ...

  3. FastDFS 配置文件 client.conf storage_ids.conf

    client.conf : # connect timeout in seconds # default value is 30s connect_timeout=30              连接 ...

  4. IP切换脚本

    1. 新建bat文件: 2. 将下面内容拷贝进bat文件: 3. 运行bat文件: @echo off color 00title IP切换脚本:start @echo --------------- ...

  5. ES[7.6.x]学习笔记(一)Elasticsearch的安装与启动

    Elasticsearch是一个非常好用的搜索引擎,和Solr一样,他们都是基于倒排索引的.今天我们就看一看Elasticsearch如何进行安装. 下载和安装 今天我们的目的是搭建一个有3个节点的E ...

  6. EF CORE中复杂类型的映射

    实体映射时,遇到复杂类型,可选择下述方法处理: NotMapped,跳过映射 在复杂类型上声明 [Owned],但仅限该复杂类型是全部由简单值类型组成的 自定义序列化方法   示例: IPInfo使用 ...

  7. leaflet结合turf.js实现多边形分割(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  8. #《Essential C++》读书笔记# 第六章 以template进行编程

    练习题答案 练习6.1 试改写以下类,使它成为一个class template: class example { public: example(double min, double max); ex ...

  9. Kong Gateway - 11 基于网关服务的ACL访问控制列表 黑名单

    Kong Gateway - 11 基于网关服务的ACL访问控制列表 黑名单 同一服务名称 book 不允许即创建白名单访问控制列表又创建黑名单访问控制列表 启用服务的白名单&黑名单配置文件时 ...

  10. request.getParameterMap获取不到数据问题

    最近在做javaweb项目的过程中发现使用request.getParameterMap( )方法获取jsp页面中的表单数据的时候发现获取不到,检查了好长时间最后发现问题是在jsp页面中. reque ...