Java多个ppt合并脚本_Apache POI PPT - 合并( Merging)

本文介绍如何使用Java和Apache POI库来合并多个PPT演示文稿。通过XMLSlideShow类的importContent()方法,可以将多个演示文稿的内容整合到一个新的PPT文件中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Apache POI PPT - 合并( Merging)

您可以使用XMLSlideShow类的importContent()方法合并多个演示文稿。 以下是合并两个演示文稿的完整程序 -import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import org.apache.poi.xslf.usermodel.XMLSlideShow;

import org.apache.poi.xslf.usermodel.XSLFSlide;

public class MergingMultiplePresentations {

public static void main(String args[]) throws IOException {

//creating empty presentation

XMLSlideShow ppt = new XMLSlideShow();

//taking the two presentations that are to be merged

String file1 = "presentation1.pptx";

String file2 = "presentation2.pptx";

String[] inputs = {file1, file2};

for(String arg : inputs){

FileInputStream inputstream = new FileInputStream(arg);

XMLSlideShow src = new XMLSlideShow(inputstream);

for(XSLFSlide srcSlide : src.getSlides()) {

//merging the contents

ppt.createSlide().importContent(srcSlide);

}

}

String file3 = "combinedpresentation.pptx";

//creating the file object

FileOutputStream out = new FileOutputStream(file3);

// saving the changes to a file

ppt.write(out);

System.out.println("Merging done successfully");

out.close();

}

}

将上面的代码保存为MergingMultiplePresentations.java ,然后从命令提示符编译并执行它,如下所示 -$javac MergingMultiplePresentations.java

$java MergingMultiplePresentations

它将编译并执行以生成以下输出 -Merging done successfully

以下快照显示了第一个演示文稿 -

25fb48eab244b77f1eb249bccaaf6d24.png

以下快照显示第二个演示文稿 -

af1f09936b1e9210cde51119e4cdaa43.png

下面给出了合并两张幻灯片后程序的输出。 在这里,您可以看到合并在一起的早期幻灯片的内容。

c35ed044eb5a89c1519b9c66f98cfd74.png

Apache POI PPT - 格式化文本( Formatting Text)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值