使用 Java 生成 PowerPoint 2007/2010 文件

发布于 2024-08-19 06:34:13 字数 203 浏览 2 评论 0原文

有谁知道任何可以通过 Java 生成/编辑 PowerPoint 2007/2010 演示文稿的 API(商业或开源)。我有一个 PowerPoint 2007/2010 格式的模板,需要编辑/更新。到目前为止,我一直将 .pptx 文件转换为 xml,然后编辑并将其存储回 .pptx。但文件在打开时被损坏。

有人知道在 Java 中执行此操作的任何其他方法或 API 吗?

Does anyone know of any API (commercial or open-source) that can generate/edit PowerPoint 2007/2010 presentations through Java. I have a template in the PowerPoint 2007/2010 format that I require to edit/update. So far I have been converting the .pptx file to xml and then editing and storing it back as .pptx. But the file gets corrupted while opening.

Is anyone aware of any other method or API that do this in Java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

执妄 2024-08-26 06:34:13

我们已经以编程方式完成了它(目前关闭源代码,抱歉),因此可能能够提供帮助,但请注意一些问题。

一是 POI 项目(至少当我们去年看到它时)相当不完整。它没有提供 PPTX 图表 - 这是我们想要的一项功能。事实上,POI 网站可能不是最新的,但它们似乎不支持 PowerPoint 20087 格式 (http ://poi.apache.org/slideshow/index.html)。每个人都推荐这个项目,但我们的评估是它对于通过 Java 生成 PowerPoint 2007 文件几乎没有用处。您的里程可能会有所不同。

当我们观察时,Apose 也有一些明显的局限性;不在 PowerPoint 2007 中制作图表对我们来说是一个阻碍问题。

另一个问题是 PowerPoint 2007 可能存在很多问题。我们有许多以编程方式生成的 PPT 文件会导致锁定,但在测试时,我们发现可以使用 PowerPoint 2007 中创建的简单 PPTX 文档(即不是我们的代码)重现崩溃和锁定。

最后,我们执行了以下操作:将“模板”PowerPoint 文件解压到一个文件夹,然后根据需要,用新值填充模板 XML,将其压缩,重命名各种元素和文件。将其作为有效的 PPTX 传递给用户。工作正常,除了人们编辑文件时 PowerPoint 崩溃之外。如果有市场,我想我们可以将代码打包为 Web 服务(即 xml/csv -> PPTX)或放在一起商业包,但我们不会免费这样做。

We have done it programmatically (closed source at the moment, sorry) so might be able to help, but beware of a few gotchas.

One is that the POI project (at least when we looked at it last year), was quite incomplete. It didn't do PPTX Charts - which is the one feature we wanted. Infact the POI site may not be upto date, but they don't appear to support PowerPoint 20087 format (http://poi.apache.org/slideshow/index.html). Everybody recommends this project, but our evaluation was that it was pretty much useless for generating PowerPoint 2007 files via Java. Your milage may vary.

Apose also had some significant limitations when we looked at it; not doing Charts in PowerPoint 2007 being the blocking issue for us.

Another issue is that PowerPoint 2007 can be quite buggy. We have had a number of progammatically produced PPT files that caused lock ups, but when testing, we found that we can repro crashes and lock ups with simple PPTX documents created in PowerPoint 2007 - i.e. not our code.

In the end, we did the following: Unpacked a 'template' PowerPoint file to a folder, then on demand, filled the template XML with new values, zipped it up, renaming various elements & delivered it to the user as a valid PPTX. Works OK, other than the odd PowerPoint crash when people edit the file. If there was a market for it, I guess we could package up the code as a webservice (i.e xml/csv -> PPTX) or put together a commerical package, but we wouldn't do it for free.

一江春梦 2024-08-26 06:34:13

docx4j(apache 许可证)现在包含一个 pptx4j 组件,可以打开/编辑/保存 pptx 文档。

docx4j (apache license) now includes a pptx4j component, which can open/edit/save pptx documents.

淡莣 2024-08-26 06:34:13

是的。查看 http://poi.apache.org/,他们刚刚发布了 3.6 版本,现在支持 Office 2007格式化文档。最好的部分是它是免费的!

Yes. Check this out http://poi.apache.org/, they just released version 3.6 which now supports Office 2007 format documents. The best part is that it's free!

停滞 2024-08-26 06:34:13

要从模板文件生成 PowerPoint 演示文稿,您可以使用 PPT 模板

该库提供了一个流畅的API来替换PPT模板内的变量:

try(FileOutputStream out = new FileOutputStream("generated.pptx")) {
  new PptMapper()
    .text("variable", "Hello")
    .text("other_variable", "World!")
    .processTemplate(PptTemplateDemo.class.getResourceAsStream("/title.pptx"))
    .write(out);
}

使用该库,您可以处理模板中的文本和图像。

To generate a PowerPoint presentation from a template file, you can use PPT Templates.

This library provides a fluent API to replace variables inside the PPT template:

try(FileOutputStream out = new FileOutputStream("generated.pptx")) {
  new PptMapper()
    .text("variable", "Hello")
    .text("other_variable", "World!")
    .processTemplate(PptTemplateDemo.class.getResourceAsStream("/title.pptx"))
    .write(out);
}

With this library, you can process text and images in the template.

缘字诀 2024-08-26 06:34:13

另一个可能适合您的解决方案是 Windward Reports (免责声明,我是创始人和首席执行官)。它使用 PPTX 作为支持的模板格式之一,并合并数据,然后生成 PPTX(或 PDF 等)输出。

如果您需要的编辑/更新可以通过 Windward 中的数据标签进行处理,那么这对您来说应该是微不足道的。如果标签无法处理您需要的内容,那么这对您不起作用。

Another solution that may work for you is Windward Reports (disclaimer, I'm the founder & CEO there). It uses PPTX as one of the supported template formats and merges in data to then generate a PPTX (or PDF, etc.) output.

If the edit/update you need can be handled via the data tags in Windward, this should be trivial for you. If what you need cannot be handled by the tags, then this won't work for you.

你另情深 2024-08-26 06:34:13

正如 GrantB 提到的,最好的方法是创建模板,然后加载模板遍历 xml 图,更新数据并输出到输出 ppt。我们最近这样做是为了为具有复杂视觉效果和 ppt 图表的客户生成报告。你可以看一下用java生成ppt

Well as mentioned by GrantB best way is to create a template, then load the template , traverse the xml graph,update the data and stream out to a output ppt. We recently did it to generate reports for clients that had complex visuals and charts in ppt. You can have a look here generate ppt in java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文