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. Keepalived 介绍 原理

    keepalived是什么: 这里先和前面的LVS 联系一下,我们平时使用一台机器运行 LVS 进行数据的转发,这里会有两个问题1.如果这台LVS 故障了怎么办?整个集群系统都会停止工作2.LVS后端 ...

  2. 1 Nginx + 12 Tomcat +2DB 实现2个程序负载均衡

    根据真实生产环境 总结. 硬件:共计5台服务器  1台负载windows.2台业务windows.2台数据库linux 业务:运行两个程序,两个数据库 具体:63服务器安装 Nginx 做负载 :61 ...

  3. Angular常用命令

    一. Angular常用命令 1. ng new 文件夹名 (新建项目,选择y使用路由) 2. ng serve --open (默认浏览器运行项目) 3. ng serve --port 6060  ...

  4. 物理机安装ESXI6.7提示No Network Adapters的解决方案

    下载好ESXI6.7.iso镜像,写入U盘后,提示No Network Adapters,找不到网卡驱动. 解决办法:需要重新封装ESXI,将对应的网卡驱动嵌入进来. 1.先下载VMware-Powe ...

  5. centos7使用MySQL的Yum存储库安装mysql5.6.45

    注意:这个MySQL5.6.45版本有问题,修改配置文件不生效,推荐安装MySQL5.6.43 下载yum源 官网地址:http://dev.mysql.com/downloads/repo/yum/ ...

  6. android手机拍照旋转的问题

    android开发中,遇到过手机拍照,明明是竖着拍的,显示的结果却是横这的,困扰了很久,找了很久找了一种解决方法: ExifInterface exifInterface = new ExifInte ...

  7. 快速筛出topK的快速选择算法和BFPRT优化

    本文始发于个人公众号:TechFlow,原创不易,求个关注 在之前Python系列当中,我们介绍了heapq这个库的用法,它可以在\(O(nlogn)\)的时间里筛选出前K大或者前K小的元素.今天我们 ...

  8. 寒假学习进度一(安卓配置环境的搭建和hello world)

    今天学习内容:观看了哔哩哔哩上的安卓教学视频,简单了解下了安卓的基本知识 具体内容: 一.配置安卓开发环境(安装Android studio,配置JDK) Android studio是个集成环境,不 ...

  9. robotframework安装与详解

    Robot Framework(以下简称rf)是一款python编写的功能自动化测试框架.具备良好的可扩展性,支持关键字驱动,可以同时测试多种类型的客户端或者接口,可以进行分布式测试执行.主要用于轮次 ...

  10. 在本地搭建git服务器

    GitHub就是一个免费托管开源代码的远程仓库.但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用. 搭建Gi ...