weixin_43043732 2023-04-19 21:47 采纳率: 0%
浏览 12

poi向PPT中插入对象

java使用POI导出ppt向ppt中插入excel,word等对象

  • 写回答

1条回答 默认 最新

  • 守时间的孤岛 2023-04-20 09:34
    关注

    该回答引用chatgpt:
    Java中可以使用Apache POI库来创建和编辑Microsoft Office文件,包括PowerPoint文件(PPT)和Excel文件(XLS)。下面是向PPT中插入Excel和Word对象的示例代码:

    向PPT中插入Excel对象

    import java.io.*;
    import org.apache.poi.hslf.usermodel.*;
    
    public class InsertExcel {
        public static void main(String[] args) throws IOException {
            // create a new PowerPoint presentation
            HSLFSlideShow ppt = new HSLFSlideShow();
    
            // create a new slide
            HSLFSlide slide = ppt.createSlide();
    
            // create a new Excel object
            HSLFObjectData excel = new HSLFObjectData(new File("path/to/excel.xls"), "Excel.Sheet.8");
    
            // set the position and size of the Excel object on the slide
            excel.setAnchor(new java.awt.Rectangle(100, 100, 500, 500));
    
            // add the Excel object to the slide
            slide.addShape(excel);
    
            // save the PowerPoint presentation
            FileOutputStream out = new FileOutputStream("path/to/presentation.ppt");
            ppt.write(out);
            out.close();
        }
    }
    
    
    

    向PPT中插入Word对象:

    
    import java.io.*;
    import org.apache.poi.hslf.usermodel.*;
    
    public class InsertWord {
        public static void main(String[] args) throws IOException {
            // create a new PowerPoint presentation
            HSLFSlideShow ppt = new HSLFSlideShow();
    
            // create a new slide
            HSLFSlide slide = ppt.createSlide();
    
            // create a new Word object
            HSLFObjectData word = new HSLFObjectData(new File("path/to/word.doc"), "Word.Document.8");
    
            // set the position and size of the Word object on the slide
            word.setAnchor(new java.awt.Rectangle(100, 100, 500, 500));
    
            // add the Word object to the slide
            slide.addShape(word);
    
            // save the PowerPoint presentation
            FileOutputStream out = new FileOutputStream("path/to/presentation.ppt");
            ppt.write(out);
            out.close();
        }
    }
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 4月19日

悬赏问题

  • ¥15 服务器清除BIOS之后引导不了
  • ¥15 CPLEX用OPL编写的混合整数线性优化问题。
  • ¥15 可以用EasyConnect连接实验室内网,但无法连接内网才能访问的服务器,为什么?
  • ¥15 前端预览docx文件,文件从后端传送过来。
  • ¥15 层次聚类和蛋白质相似度
  • ¥25 主成分分析中的第一第二主成分分别代表哪些参数
  • ¥15 oracle数据库查询语句问题
  • ¥15 有没有c++绘制算法的佬们吗救孩一下
  • ¥15 android 蓝牙闪退
  • ¥15 绝缘子污秽comsol仿真参数