POI接口获取PPT获取每一页的内容,创建页、复制页,往某页指定位置插入图片

本文档详细介绍了如何使用Java的POI库来操作PPT文件,包括导入相关依赖,创建新的PPT页面,获取每一页的内容,复制现有页面以及在特定位置插入图片。特别强调了在执行这些操作时,必须正确处理输出流以确保数据的完整保存。
摘要由CSDN通过智能技术生成

一、导入pom依赖

<dependency>
        <groupId>org.apache.poi</groupId>
         <artifactId>poi</artifactId>
        <version>3.17</version>   
 </dependency>
 <dependency>
        <groupId>org.apache.poi</groupId>        
​​​​​​​         <artifactId>poi-ooxml</artifactId>
         <version>3.17</version>
     </dependency>
<!-- 读取PPT-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.17</version>
        </dependency>

二、创建新页省略

三、获取PPT每一页的内容

 public static void main(String[] args) {
        XMLSlideShow ppt = null;
        try {
            // PPT类
            ppt = new XMLSlideShow(new FileInputStream("d:/test/test01.pptx"));
            // 获取PPT中的所有幻灯片
//            List<XSLFSlide> slides = ppt.getSlides();
            // 遍历幻灯片
            for(int i = 0;i < ppt.getSlides().size();i++) {
                //拿到第i页的PPT
                XSLFSlide slides = ppt.getSlides().get(i);
                System.out.println("第"+(i+1)+"页")
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用Python中的openpyxl模块来复制一个Excel文件中的sheet及其内容格式到另一个Excel文件中。具体步骤如下: 1. 导入openpyxl模块和copy模块: ```python import openpyxl from openpyxl.utils import get_column_letter from openpyxl.styles import Color, PatternFill, Font, Border from copy import copy ``` 2. 打开原始Excel文件和目标Excel文件,并获取需要复制的sheet: ```python # 打开原始Excel文件 wb_source = openpyxl.load_workbook('source.xlsx') # 打开目标Excel文件 wb_dest = openpyxl.load_workbook('dest.xlsx') # 获取需要复制的sheet ws_source = wb_source['Sheet1'] ``` 3. 创建一个新的sheet复制原始sheet内容和格式: ```python # 创建一个新的sheet ws_dest = wb_dest.create_sheet('Sheet1') # 复制原始sheet内容和格式 for row in ws_source.iter_rows(): for cell in row: new_cell = ws_dest.cell(row=cell.row, column=cell.column, value=cell.value) if cell.has_style: new_cell.font = copy(cell.font) new_cell.border = copy(cell.border) new_cell.fill = copy(cell.fill) new_cell.number_format = copy(cell.number_format) new_cell.protection = copy(cell.protection) new_cell.alignment = copy(cell.alignment) ``` 4. 保存目标Excel文件: ```python # 保存目标Excel文件 wb_dest.save('dest.xlsx') ``` 这样,你就可以成功地将一个Excel文件中的sheet及其内容格式复制到另一个Excel文件中了。注意,如果有多个sheet需要复制,可以使用循环来实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值