当前位置: 首页> 科技> 能源 > sem优化专员_百度网站怎么优化排名靠前_各大网站提交入口_网络热词

sem优化专员_百度网站怎么优化排名靠前_各大网站提交入口_网络热词

时间:2025/9/10 11:01:01来源:https://blog.csdn.net/lqz1993/article/details/144240255 浏览次数:0次
sem优化专员_百度网站怎么优化排名靠前_各大网站提交入口_网络热词

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.sl.usermodel.PictureData;
import org.apache.poi.sl.usermodel.PictureShape;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.xslf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTable;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;public class PPTGenerator {public static void main(String[] args) {try {String templatePath = "C:\\Users\\Lenovo\\Desktop\\333.pptx";String outputPath = "C:\\Users\\Lenovo\\Desktop\\222.pptx";XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(templatePath));Map<String, String> textMap = new HashMap<String, String>();textMap.put("text1", "上周,全国统调电厂日均供煤752万吨,日均耗煤713万吨,当前库存22901万吨,达到去年极值的109%,可用32天,同比增加2天。");textMap.put("text2", "国网统调电厂日均供煤663万吨,日均耗煤633万吨,当前库存19521万吨,达到去年极值的107%,可用31天,同比增加2天。四川电煤库存上升至567万吨,完成度冬储煤目标。");List<List<String>> tableList = new LinkedList<List<String>>();List<String> rowList = new LinkedList<String>();rowList.add("湖北");rowList.add("623");rowList.add("618");rowList.add("0.93%");rowList.add("35");tableList.add(rowList);tableList.add(rowList);List<String> imageList = new LinkedList<>();imageList.add("C:\\Users\\Lenovo\\Desktop\\图片1.jpg");int imageNum = 0;//;图片是按顺序替换for (XSLFSlide slide : ppt.getSlides()) {for (XSLFShape shape : slide.getShapes()) {if (shape instanceof XSLFTextShape) {XSLFTextShape textShape = (XSLFTextShape) shape;List<XSLFTextParagraph> paragraphs = textShape.getTextParagraphs();for (XSLFTextParagraph paragraph : paragraphs) {List<XSLFTextRun> runs = paragraph.getTextRuns();for (XSLFTextRun run : runs) {String textToReplace = run.getRawText();String textValue = textMap.get(textToReplace);if (StringUtils.isBlank(textValue)){continue;}textToReplace = textToReplace.replace(textToReplace, textValue);run.setText(textToReplace);}}} else if (shape instanceof XSLFTable) {// 检查形状是否是表格XSLFTable table = (XSLFTable) shape;List<XSLFTableRow> rows = table.getRows();for (int i = 0; i < tableList.size(); i++) {XSLFTableRow row = table.getRows().get(i+1);for (int j = 0; j < tableList.get(i).size(); j++) {XSLFTableCell cell = row.getCells().get(j);cell.clearText();
//                                cell.setText(tableList.get(i).get(j));XSLFTextParagraph paragraph = cell.addNewTextParagraph();paragraph.setTextAlign(TextParagraph.TextAlign.CENTER);XSLFTextRun run = paragraph.addNewTextRun();run.setText(tableList.get(i).get(j));// 设置字体样式run.setFontFamily("黑体"); // 设置字体名称run.setFontSize(9.0); // 设置字体大小
//                                run.setBold(true); // 设置加粗
//                                run.setItalic(true); // 设置斜体// 如果需要设置字体颜色,可以使用以下代码(这里使用RGB颜色)
//                                run.setFontColor(new java.awt.Color(255, 0, 0)); // 红色字体}}//删除多余的预留空白行while (tableList.size()+1<rows.size()){table.removeRow(tableList.size()+1);}} else if (shape instanceof XSLFPictureShape) {// 检查形状是否是图片byte[] imageData = Files.readAllBytes(Paths.get(imageList.get(imageNum)));PictureData pictureData = ((PictureShape) shape).getPictureData();pictureData.setData(imageData);imageNum++;}}}FileOutputStream out = new FileOutputStream(outputPath);ppt.write(out);} catch (Exception e) {e.printStackTrace();}System.out.println("PPT generated successfully!");}
}

maven依赖

<dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.3</version> <!-- 请使用最新版本 --></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.4</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.11.0</version> <!-- 选择一个合适的版本 --></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.xmlbeans</groupId><artifactId>xmlbeans</artifactId><version>5.1.1</version></dependency>
关键字:sem优化专员_百度网站怎么优化排名靠前_各大网站提交入口_网络热词

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: