How do I programmatically save a document in OpenOffice.org?

时间秒杀一切 提交于 2019-12-13 12:30:18

问题


I'd like to save a TextDocument created through OpenOffice.org UNO to a file on the disk. What is the best way to do this?

Edit: This is the C# code that I ended up using. document is an XTextDocument.

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

回答1:


Use XStorable.storeToURL() (or storeAsURL).

Edit: You need to pass a FilterName with the output format. Example (in Python 'cause that's simpler):

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


来源:https://stackoverflow.com/questions/2022846/how-do-i-programmatically-save-a-document-in-openoffice-org

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!