我使用 Java 中的 UNO 来控制 LibreOffice (5.3)。
如何更改窗口标题栏中显示的文档名称?
到目前为止,我尝试使用 XDocumentProperties
,但它仅在文档的嵌入属性中设置标题,而不是在窗口标题中设置标题:
// Sets only meta data, not the window title.
XDocumentPropertiesSupplier xDocumentPropertiesSupplier = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, openedDocument);
XDocumentProperties xDocumentProperties = xDocumentPropertiesSupplier.getDocumentProperties();
xDocumentProperties.setTitle(retrievedFile.name);
最佳答案
通常,只需从 XStorable 调用 storeAsURL
.
但是,对于流式传输等特殊情况,您可能需要使用 XDocumentProperties 。调用 setTitle()
,如 https://forum.openoffice.org/en/forum/viewtopic.php?f=25&t=70156 中的以下 C++ 代码所示.
Reference<XModel> xModel(xComponent, UNO_QUERY);
Reference<XTitle> xTitle(xModel, UNO_QUERY);
xTitle->setTitle(constOUString("Title"));
编辑:
这是XTitle来自您拒绝的编辑的代码。
XTitle xTitle = UnoRuntime.queryInterface(XTitle.class, xComponent /* e.g. from xComponentLoader.loadComponentFromURL(...) */);
xTitle.setTitle("Title");
注意:正如审稿人所写,这应该添加到评论或单独的答案中,而不是编辑。在这个网站上编辑别人的代码几乎从来都不是一个好主意。但是,回答您自己的问题是完全可以接受的。
关于java - 如何通过UNO更改文档名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50434950/