try {
            // 获取PPT文件
             String pptModelPath =ConfigReadUtil.getInstance().getConfigItem("ppt_path");  //获取路径
            FileInputStream is = new FileInputStream(pptModelPath+"2.pptx");  //读pptx存放的路径

XMLSlideShow ppt = new XMLSlideShow(is);

is.close();

for (XSLFSlide slide : ppt.getSlides()) {
                // 获取每一张幻灯片中的shape
                for (XSLFShape shape : slide.getShapes()) {
                    Rectangle2D anchor = shape.getAnchor();
                    if (shape instanceof XSLFTextShape) {
                        XSLFTextShape txShape = (XSLFTextShape) shape;
                        if (txShape.getText().contains("{time}")) {
                            // 替换文字内容
                            txShape.setText(txShape.getText().replace(
                                    "{time}", time1));
                        }else if (txShape.getText().contains("{eight}")) {
                            // 替换文字内容
                            txShape.setText(txShape.getText().replace(
                                    "{eight}", finalTime));
                        }else if (txShape.getText().contains("{pic}")) {  //替换图片
                             byte[] pictureData = IOUtils.toByteArray(new FileInputStream("C:\\Users\\gls\\Desktop\\1.jpg"));
                             int idx = ppt.addPicture(pictureData,XSLFPictureData.PICTURE_TYPE_PNG);
                            XSLFPictureShape pic = slide.createPicture(idx);
                             // 设置XSLFPictureShape的位置信息
                             pic.setAnchor(anchor);
                             // 移除XSLFTextShape
                             slide.removeShape(txShape);
                        }
                        else if (txShape.getText().contains("{today}")) {
                            // 替换文字内容
                            txShape.setText(txShape.getText().replace(
                                    "{today}", firstTime));
                        } else if (txShape.getText().contains("{tomorrow}")) {
                            // 替换文字内容
                            txShape.setText(txShape.getText().replace(
                                    "{tomorrow}", secondTime));
                        }else if (txShape.getText().contains("{the day after tomorrow}")) {
                            // 替换文字内容
                            txShape.setText(txShape.getText().replace(
                                    "{the day after tomorrow}", thirdTime));
                        }
                        else if (txShape.getText().contains("{dwfirstRain}")) {
                            // 替换文字内容
                            txShape.setText(txShape.getText().replace(
                                    "{dwfirstRain}", dwfirstRain));
                        } else if (txShape.getText().contains("{psfirstRain}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psfirstRain}", psfirstRain));
                        } else if (txShape.getText().contains("{dwsecondRain}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwsecondRain}",dwsecondRain));
                        } else if (txShape.getText().contains("{pssecondRain}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{pssecondRain}", pssecondRain));
                        } else if (txShape.getText().contains("{dwthirdRain}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwthirdRain}",dwthirdRain));
                        } else if (txShape.getText().contains("{psthirdRain}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psthirdRain}",psthirdRain));
                        } else if (txShape.getText().contains("{dwFirstphenomena}")) {
                            txShape.setText(txShape.getText().replace("{dwFirstphenomena}",
                                    dwFirstphenomena));
                        } else if (txShape.getText().contains("{psFirstphenomena}")) {
                            txShape.setText(txShape.getText().replace("{psFirstphenomena}",
                                    psFirstphenomena));
                        } else if (txShape.getText().contains("{dwSecondphenomena}")) {
                            txShape.setText(txShape.getText().replace("{dwSecondphenomena}",
                                    dwSecondphenomena));
                        } else if (txShape.getText().contains("{psSecondphenomena}")) {
                            txShape.setText(txShape.getText().replace("{psSecondphenomena}",
                                    psSecondphenomena));
                        } else if (txShape.getText().contains("{dwThirdphenomena}")) {
                            txShape.setText(txShape.getText().replace("{dwThirdphenomena}",
                                    dwThirdphenomena));
                        } else if (txShape.getText().contains("{psThirdphenomena}")) {
                            txShape.setText(txShape.getText().replace("{psThirdphenomena}",
                                    psThirdphenomena));
                        } else if (txShape.getText().contains("{dwfirstMaxTemp}")) {
                            txShape.setText(txShape.getText().replace("{dwfirstMaxTemp}",
                                    dwfirstMaxTemp));
                        } else if (txShape.getText().contains("{psfirstMaxTemp}")) {
                            txShape.setText(txShape.getText().replace("{psfirstMaxTemp}",
                                    psfirstMaxTemp));
                        } else if (txShape.getText().contains("{dwsecondMaxTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwsecondMaxTemp}", dwsecondMaxTemp));
                        }else if (txShape.getText().contains("{pssecondMaxTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{pssecondMaxTemp}", pssecondMaxTemp));
                        }else if (txShape.getText().contains("{dwthirdMaxTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwthirdMaxTemp}", dwthirdMaxTemp));
                        }else if (txShape.getText().contains("{psthirdMaxTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psthirdMaxTemp}", psthirdMaxTemp));
                        }else if (txShape.getText().contains("{dwfirstMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwfirstMinTemp}", dwfirstMinTemp));
                        }else if (txShape.getText().contains("{psfirstMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psfirstMinTemp}", psfirstMinTemp));
                        }else if (txShape.getText().contains("{dwsecondtMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwsecondtMinTemp}", dwsecondtMinTemp));
                        }else if (txShape.getText().contains("{pssecondMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{pssecondMinTemp}", pssecondMinTemp));
                        }else if (txShape.getText().contains("{dwthirdMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwthirdMinTemp}", dwthirdMinTemp));
                        }else if (txShape.getText().contains("{psthirdMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psthirdMinTemp}", psthirdMinTemp));
                        }else if (txShape.getText().contains("{dwWindDAndV}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwWindDAndV}", dwWindDAndV));
                        }else if (txShape.getText().contains("{psWindDAndV}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psWindDAndV}", psWindDAndV));
                        }else if (txShape.getText().contains("{dwSeaWindDAndV}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{dwSeaWindDAndV}", dwSeaWindDAndV));
                        }else if (txShape.getText().contains("{psSeaWindDAndV}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{psSeaWindDAndV}", psSeaWindDAndV));
                        }else if (txShape.getText().contains("{zyPSMaxTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyPSMaxTemp}", zyPSMaxTemp));
                        }else if (txShape.getText().contains("{zyPSMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyPSMinTemp}", zyPSMinTemp));
                        }else if (txShape.getText().contains("{zyPSPhoenomena}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyPSPhoenomena}", zyPSPhoenomena));
                        }else if (txShape.getText().contains("{zyPSWindD}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyPSWindD}", zyPSWindD));
                        }else if (txShape.getText().contains("{zyPSWindV}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyPSWindV}", zyPSWindV));
                        }else if (txShape.getText().contains("{zyDWMaxTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyDWMaxTemp}", zyDWMaxTemp));
                        }else if (txShape.getText().contains("{zyDWMinTemp}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyDWMinTemp}", zyDWMinTemp));
                        }else if (txShape.getText().contains("{zyDWPhoenomena}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyDWPhoenomena}", zyDWPhoenomena));
                        }else if (txShape.getText().contains("{zyDWWindD}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyDWWindD}", zyDWWindD));
                        }else if (txShape.getText().contains("{zyDWWindV}")) {
                            txShape.setText(txShape.getText().replace(
                                    "{zyDWWindV}", zyDWWindV));
                        }
                    }  else if (shape instanceof XSLFPictureShape) {
                        XSLFPictureShape pShape = (XSLFPictureShape) shape;
                        XSLFPictureData pData = pShape.getPictureData();
                    } else {
                        System.out.println("Process me: " + shape.getClass());
                    }
                }
            }

Object user = ServletActionContext.getRequest().getSession()
                    .getAttribute(ResourceUtil.getSessionInfoName());
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
            SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
            String fileTime = sdf.format(date);
            String time= s.format(date);
             String filePath =ConfigReadUtil.getInstance().getConfigItem("FileSavePath");
        //    String filePath = "D:\\Conference";
            filePath = filePath.replace("\\", "\\\\");

File dir = new File(filePath);
            if(!dir.exists()){
                dir.mkdirs();
            }
            String path = dir.getPath();
            path = path.replace("\\", "\\\\");
            String fileName = "天气会商.pptx";

String fileType = "pptx";
            WeatherConference c = new WeatherConference();
            c.setFileName(time+fileName);
            c.setFileType(fileType);
            c.setFileTime(fileTime);
            c.setFileUploader(user.toString());
            c.setFilePath(path+"\\\\"+time+"天气会商制作"+".pptx");
            conferenceManager.add(c);

FileOutputStream out = new FileOutputStream(path+"\\"+time+"天气会商制作"+".pptx");

ppt.write(out);
            out.close();

用poi替换ppt中的文字和图片的更多相关文章

  1. poi读取docx中的文字和图片(自己应用)

    poi读取docx中的文字和图片(自己应用) package com.fry.poiDemo.dao; import java.io.File; import java.io.FileInputStr ...

  2. poi提取docx中的文字和图片

    package com.fry.poiDemo.dao; import java.io.File; import java.io.FileInputStream; import java.io.Fil ...

  3. 如何提取出ppt中的文字?

    最近在看一位老师的教学视频,视频里大部分的知识都记录在ppt里,于是很想将ppt中的文字提取出来,如果我一页一页地粘贴复制的话,效率低到吓人,因为一章的ppt有130多页,于是在网上搜索了一下方法,与 ...

  4. 使用POI替换word中的特定字符/文字改进版

    package com.xfzx.test.POI.main; import java.io.File; import java.io.FileInputStream; import java.io. ...

  5. C# 使用正则表达式替换PPT中的文本(附vb.net代码)

    文本介绍如何在C#程序中使用正则表达式替换PPT幻灯片中的指定文本内容.具体操作步骤如下: 1. 在程序中引用Spire.Presentation.dll.两种方法可参考如下: (1)直接在程序中通过 ...

  6. Java在已存在的pdf文件中生成文字和图片--基础

    自我总结,有什么不足之处请告知,感激不尽!下一次总结pdf模板映射生成报表(应对多变的pdf报表需求,数据提供和报表生成解耦). 目的:在给定的pdf模板上生成报表,就需要知道最基本的操作:文字添加, ...

  7. 批量导出ppt中内嵌的图片

    某个ppt中很多页,然后插入了很多图片,且图片都是被压缩的,看起来非常费劲,所以想着一次性把图片另存为,找了接近一个小时,终于被我找到啦,分享给大家: 1.直接把ppt的后缀修改为rar 2.解压ra ...

  8. PDFtoWORD_V1.1版本支持PDF文档中的文字和图片一起转化到word文档中了~

    ​    昨天菜鸟小白做了一个小软件——PDFtoWORD,作用就是将pdf文件中的文字提取出来自动转化为可编辑的word类型.但是这个软件目前也只能将文件PDF中的文字提取出来,还无法提取图片.为了 ...

  9. 如何用Python输出PPT中的文字信息

    在这里,会用到win32com模块 模块下载地址:http://sourceforge.net/projects/pywin32/files/pywin32/ 代码如下: import win32co ...

随机推荐

  1. VIVADO生成MCS

    tcl console里面执行 write_cfgmem -format mcs -interface spix4 -size 128 -loadbit "up 0 E:/x.bit&quo ...

  2. Ubuntu不能上网解决办法

     一.设置IP.网关.DNS 新安装的Ubuntu系统ifconfig后发现没有ip,所以要设置IP.网关.DNS等,编辑 /etc/networking/interfases sudo vi /et ...

  3. windows下go调用内存dll

    有时候我们希望将dll嵌入到程序内部,以提高程序的安全性,这里我写的一个开源memorydll模块. 首先 go get github.com/nkbai/go-memorydll 然后在需要的时候 ...

  4. html5 video微信浏览器视频不能自动播放

    html5 video微信浏览器视频不能自动播放 一.微信浏览器(x5内核): 1.不能自动播放 2.全屏 3.最顶层(z层的最顶层) 二.ios系统解决方案:(无phone手机未测试) <au ...

  5. Android TV 开发 (1)

    本文来自网易云社区 作者:孙有军 前言 这里主要记录几个TV问题的解决方案,如果对这个不感兴趣的其实就不用往下看了. 这几天有一个需求就是要求出一个TV版本的app,之前没有具体的了解Tv版的app有 ...

  6. 「BZOJ 3209」花神的数论题

    Title Link 戳我 Title Solution 这道题可以运用组合数的思想啊,数位dp也可以,随便你怎么做,这里就讲一讲组合数的做法吧,要小于n,所以我们可以枚举n二进制下1的位置,在i-1 ...

  7. openvpn的搭建与应用

    一.VPN概述: VPN(Virtual Private NetWork,虚拟专用网络)架设在公共共享的基础设施互联网上,在非信任的网络上建立私有的安全的连接,把分布在不同地域的办公场所.用户或者商业 ...

  8. 基于openstack搭建百万级并发负载均衡器的解决方案

    最近,喜欢研究一些国外技术大咖们的文章,而这篇文章是基于openstack负载均衡器的解决方案,做的一些总结~希望能够给小伙伴带来一些灵感或者帮助. openstack现有的负载均衡解决方案,无论是l ...

  9. networkx如何将图写到邻接矩阵里?

    nx.write_adjlist(G1,graph_filename1)#生成的是二进制文件nx.write_adjlist(G2,graph_filename2)

  10. Java_Ant详解(转载)

    Java_Ant详解   1,什么是antant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant ...