您的位置:首页 > 教育 > 锐评 > 网络营销专业如何_免费推广手段有哪些_写文案接单平台_seo营销培训

网络营销专业如何_免费推广手段有哪些_写文案接单平台_seo营销培训

2025/3/18 20:47:29 来源:https://blog.csdn.net/jjruanlili/article/details/146317069  浏览:    关键词:网络营销专业如何_免费推广手段有哪些_写文案接单平台_seo营销培训
网络营销专业如何_免费推广手段有哪些_写文案接单平台_seo营销培训

注意,不涉及图片处理。

先上pom依赖:

        <!-- 处理PPTX文件 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>5.2.3</version></dependency><!-- 处理PPT文件 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>5.2.3</version></dependency>

代码:

public static void main(String[] args) {String filePath = "C:\\xx.pptx"; // 待处理ppt全路径try {IOUtils.setByteArrayMaxOverride(160000000);//分配内存160MString content = readPresentation(filePath);System.out.println(content);} catch (Exception e) {e.printStackTrace();}}public static String readPresentation(String filePath) throws Exception {if (filePath.toLowerCase().endsWith(".pptx")) {return readPPTX(filePath);} else if (filePath.toLowerCase().endsWith(".ppt")) {return readPPT(filePath);}throw new IllegalArgumentException("Unsupported file format");}// 处理PPTX文件private static String readPPTX(String filePath) throws Exception {StringBuilder content = new StringBuilder();XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(filePath));for (XSLFSlide slide : ppt.getSlides()) {for (XSLFShape shape : slide.getShapes()) {if (shape instanceof XSLFTextShape) {content.append(((XSLFTextShape) shape).getText()).append("\n");}}}return content.toString();}// 处理PPT文件private static String readPPT(String filePath) throws Exception {StringBuilder content = new StringBuilder();try (HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(filePath))) {for (HSLFSlide slide : ppt.getSlides()) {// 读取幻灯片中的形状for (HSLFShape shape : slide.getShapes()) {if (shape instanceof HSLFTextShape) {HSLFTextShape textShape = (HSLFTextShape) shape;content.append(textShape.getText()).append("\n");}}// 读取幻灯片中的文本框(兼容旧版本)for (List<HSLFTextParagraph> textParagraphs : slide.getTextParagraphs()) {for (HSLFTextParagraph para : textParagraphs) {content.append(para).append("\n");}}}}return content.toString();}

 最终效果与wps自带的ppt转word只勾选文本差不多。

版权声明:

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

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