gpt4 book ai didi

apache-poi - 使用 XSLF(Apache POI 项目)向 Powerpoint 幻灯片添加形状

转载 作者:行者123 更新时间:2023-12-03 16:46:24 25 4
gpt4 key购买 nike

apache POI 项目解释了如何从 powerpoint 幻灯片中读取形状 http://poi.apache.org/slideshow/xslf-cookbook.html#GetShapes

但是,我找不到任何关于如何使用库的这一部分向 powerpoint 幻灯片添加形状的文档。如果我使用旧的 powerpoint 格式(ppt 而不是 pptx),我可以只使用 libaray 的 hslf 部分并执行:

SlideShow ppt = new SlideShow();
//add first slide
Slide s1 = ppt.createSlide();

// create shapes./
java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath();
path.moveTo(100, 100);
path.lineTo(200, 100);
path.curveTo(50, 45, 134, 22, 78, 133);
path.curveTo(10, 45, 134, 56, 78, 100);
path.lineTo(100, 200);
path.closePath();

Freeform shape = new Freeform();
shape.setPath(path);
s1.addShape(shape);

//save changes in a file
FileOutputStream out;
try {
out = new FileOutputStream("slideshow.ppt");
ppt.write(out);
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException ex) {
e.printStakTrace();
}

我如何使用库的 xlsf 部分做类似的事情,从而生成 pptx?

谢谢

最佳答案

其实挺像的...

XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide s1 = ppt.createSlide();

// create shapes
java.awt.geom.Path2D.Double path = new java.awt.geom.Path2D.Double();
path.moveTo(100, 100);
path.lineTo(200, 100);
path.curveTo(50, 45, 134, 22, 78, 133);
path.curveTo(10, 45, 134, 56, 78, 100);
path.lineTo(100, 200);
path.closePath();

XSLFFreeformShape shape = s1.createFreeform();
shape.setPath(path);
shape.setLineWidth(1);
shape.setLineColor(Color.BLACK);

//save changes in a file
FileOutputStream out;
try {
out = new FileOutputStream("slideshow.pptx");
ppt.write(out);
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}

更多示例和Graphics2D你可以画画的上下文,看看我的PptxGraphics2D类。

关于apache-poi - 使用 XSLF(Apache POI 项目)向 Powerpoint 幻灯片添加形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14652821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com