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.setT