poi 3.17 资料为 demo + 模板 + 数据类 java 导出多数据 雷达图图表 到ppt
1
poi 版本 3.17 文件中包含 模板 测试main 数据类 需要调整下 路径 /** * @Description: * @Author: xsr * @date : 2018/7/22 9:41 */ public static void makePiePpt(List dataList) throws Exception { //打开模板ppt String mtemplateName = "E:/PIE/mtemplate/PIE" + dataList.size() + ".pptx"; String path ="E:/PIE/NewPPT/NewPIE" + dataList.size() + ".pptx"; XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(mtemplateName)); pptx.setPageSize(new Dimension(960, 580)); for (int i = 0; i < dataList.size(); i++) { makePiePpt(pptx, i, dataList); } //保存文件 OutputStream out = new FileOutputStream(path); pptx.write(out); out.close(); System.out.println("导出成功"); } /** * @Description: * @Author: xsr * @date : 2018/7/27 5:41 */ public static void makePiePpt(XMLSlideShow pptx, Integer pieNum, List dataList) throws Exception { //获取第一个ppt页面 XSLFSlide slide = pptx.getSlides().get(0); //遍历第一页元素找到图表 XSLFChart chart; List poixmlDocumentParts = new ArrayList(); for (POIXMLDocumentPart part : slide.getRelations()) { if (part instanceof XSLFChart) { chart = (XSLFChart) part; poixmlDocumentParts.add(chart); } } chart = (XSLFChart) poixmlDocumentParts.get(pieNum); POIXMLDocumentPart xlsPart = chart.getRelations().get(0); //把图表绑定到Excel workbook中 XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet(); CTChart ctChart = chart.getCTChart(); CTPlotArea plotArea = ctChart.getPlotArea(); CTPieChart pieChart = plotArea.getPieChartArray(0); // 获取图表的系列 CTPieSer ser = pieChart.getSerArray(0); XSSFRow row0 = sheet.createRow(0); // Series Text CTSerTx tx = ser.getTx(); tx.getStrRef().
2019-12-21 18:52:59 297KB poi 多个饼状图 导出图表ppt poi导出ppt
1