如何以编程方式从 Calc 宏打开和修改 ODT 文件

How to programmatically open and modify ODT file from Calc Macro

我正在 LibreOffice Calc 电子表格中编写宏程序。该宏应该执行以下操作(除其他外):

这是否可能仅使用 LibreOffice Basic?我在 Libreoffice 文档和示例中没有找到任何东西,只有这个稍微相关的答案在这里:How to programatically modify Open/Libre Office odt document? 谢谢!

open an existing ODT text document as a template

打开文档的方法是loadComponentFromURL, for example https://help.libreoffice.org/6.4/en-US/text/sbasic/shared/stardesktop.html。从 Calc 宏在 Writer 中打开文档没有什么特别困难的,因为 LibreOffice 组件集成得很好。请记住使用打开文档返回的对象而不是 ThisComponent.

search and replace some strings with new values

Andrew's Macro Document7.14。搜索和替换 展示了一些方法。

save a copy of this as a new file

命令是storeAsURL,类似于“另存为”,不要与会修改现有文件的storeToURL 混淆。参见 https://wiki.openoffice.org/wiki/Saving_a_document

generate and open a PDF version

生成 PDF 就像任何其他保存一样。唯一的区别是必须指定导出过滤器 writer_pdf_Export。示例位于 https://ask.libreoffice.org/en/question/178818/how-i-export-pdf-using-macro/.

关于打开PDF,您要用什么应用程序打开? LibreOffice Draw 可以打开 PDF,但它不是普通的 PDF 查看器。 Shell 可以调用您选择的查看器。