How to create .odt files with C#.NET?

后端 未结 6 1217
粉色の甜心
粉色の甜心 2020-12-31 23:58

Note: I found this \"Creating a Word Doc in C#.NET\", but that is not what I want.

Do you know how to create a .odt to create file from C#

6条回答
  •  猫巷女王i
    2021-01-01 00:40

    The code would look like this:

    private XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
    XMultiServiceFactory oServMan = (XmultiServiceFactory) oStrap.getServiceManager();
    XComponentLoader oDesk = (XComponentLoader) oServMan.createInstance("com.sun.star.frame.Desktop");
    string url = @"private:factory/swriter";
    PropertyValue[] propVals = new PropertyValue[0];
    XComponent oDoc = oDesk.loadComponentFromURL(url, "_blank", 0, propVals);
    string docText = "File Content\n\r";
    ((XTextDocument)oDoc).getText().setString(docText);
    string fileName = @"C:\FolderName\FileName.odt";
    fileName = "file:///" + fileName.Replace(@"\", "/");
    ((XStorable)oDoc).storeAsURL(fileName, propVals);
    ((Xcomponent)oDoc).dispose();
    

提交回复
热议问题