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

后端 未结 6 1176
粉色の甜心
粉色の甜心 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条回答
  • 2021-01-01 00:16

    I found this one yesterday when looking for a way to create Spreadsheeets, it looks like creating writer files is quite similar: http://www.suite101.com/content/creating-an-openoffice-calc-document-with-c-a124112, dont forget to install the Open Office SDK from Oracle first.

    Unfortunately I have not found a way to create a file without opening it yet.

    0 讨论(0)
  • 2021-01-01 00:28

    You can check out the OASIS Standards site for information on the ODT standard. From what I've seen, they're using an XML based standard and have an XSD available for the the document standard, so you could use that in conjunction with your own code to build a document file in the proper format.

    0 讨论(0)
  • 2021-01-01 00:28

    You might be interested in OpenOffice, UNO CLI Language Binding.

    0 讨论(0)
  • 2021-01-01 00:35

    OpenOffice documents (odt) are ZIP files. You can unzip an existing one, modify the content.xml file by code and then use the ZipFile class from System.IO.Compression for example to get a zip file again. Open Office Specification

    0 讨论(0)
  • 2021-01-01 00:39

    Have a look at AODL (see http://odftoolkit.org/projects/odftoolkit/pages/AODL).

    • fully managed .NET 1.1 (so it runs on MS.Net and Mono)
    • support for text and spreadsheet documents
    • create, read, edit, save documents
    • ...

    EDIT by kame: New link AODL-Wiki

    0 讨论(0)
  • 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();
    
    0 讨论(0)
提交回复
热议问题