【问题标题】:How do I programmatically save a document in OpenOffice.org?如何以编程方式在 OpenOffice.org 中保存文档?
【发布时间】:2011-01-02 15:08:42
【问题描述】:

我想将通过 OpenOffice.org UNO 创建的 TextDocument 保存到磁盘上的文件中。最好的方法是什么?

编辑:这是我最终使用的 C# 代码。 documentXTextDocument

protected void Save (string path)
{
    string url = "file://" + path;
    PropertyValue [] propertyValues = {
        new PropertyValue {
            Name = "FilterName",
            Value = new Any ("writer8")
        }
    };
    ((XStorable) document).storeAsURL (url, propertyValues);
}

【问题讨论】:

  • 我在用 C# 工作,但如果你用其他语言回答,我可以将它翻译成 C#。
  • 小心你想要的 - ++++[>+++++[-]+[>+>+ >[>-]>>>[-]++>[-]+>>>+[[-]++++++> >>]>-]+<.>---->>>>[>>>[-]++ +++++++-[-[-]+[+]
  • 不知道 OOo 在 BF 中是否可以编写脚本。

标签: c# openoffice.org uno


【解决方案1】:

使用XStorable.storeToURL()(或storeAsURL)。

编辑:您需要使用输出格式传递FilterName。示例(在 Python 中,因为这更简单):

properties = ( PropertyValue('FilterName', 0, 'writer8', 0), )
document.storeToURL('file:///path/to/document.odt', properties)

【讨论】:

  • storeToURL ()storeAsURL () 需要 2 个参数,尽管文档说第二个是可选的。我尝试将null 作为第二个传递,但我得到了一个 IOException。我现在正在查看文档,但你知道如何解决这个问题吗?如果我能弄清楚如何设置文档的默认 URL,我可以使用 store () 方法并避免整个问题。
  • 谢谢,这很好用。我将此代码的 C# 版本添加到我的问题中。
猜你喜欢
  • 2010-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-04
  • 2010-12-16
  • 1970-01-01
  • 2014-07-09
相关资源
最近更新 更多