我应该如何使用poi将word文档中的字符串替换为另一个字符串?

发布于 2024-09-17 08:43:30 字数 54 浏览 1 评论 0 原文

我是 poi 新手。我需要使用 poi 开发和编辑 Word 文档。请发送上述问题的任何示例。

i new to poi.i have a requirement to develop and edit the word document using poi.please send any sample examples for above question.

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

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

发布评论

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

评论(1

七月上 2024-09-24 08:43:30

XWPF:请参阅我关于 POI 的博客文章的第 1 部分和第 2 部分,此处:http://tkgospodinov.com/writing-microsoft-word-documents-in-java-with-apache-poi/。您可以使用 XWPFDocument#setParagraph 用 POI 替换整个段落,这样您就可以获取要替换文本的段落,并使用结果创建一个新段落并将其设置在原始段落的位置。请记住,这是自 3.7-beta2 以来的新 API。我知道这有点复杂,但目前这是实现这一目标的唯一方法。

XWPF: See part 1 and 2 of my blog post on POI, here: http://tkgospodinov.com/writing-microsoft-word-documents-in-java-with-apache-poi/. You can use XWPFDocument#setParagraph to replace a whole paragraph with POI, so you can get the paragraph where you want to replace text, and create a new paragraph with the result and set it in place of the original. Keep in mind that this is new API since 3.7-beta2. I know it's a little convoluted, but currently that is the only way to accomplish that.

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