How to create .odt files with C#.NET?
Asked Answered
D

6

8

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# .NET?
Is there a .NET component or wrapper for an OpenOffice.org library to do this?

Dissever answered 21/10, 2008 at 22:30 Comment(0)
R
3

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

Redemption answered 5/1, 2009 at 20:13 Comment(1)
The official version of AODL for .NET is not available anymore. But there a some forks you can still use. The best forks I found (with addional fixes of the authors) are aodl-reloaded and aodl. But I know there are still some issues using current versions of OpenOffice/LibreOffice.Tarr
G
2

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.

Gretchen answered 21/10, 2008 at 22:43 Comment(0)
C
2

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

Chokecherry answered 21/10, 2008 at 23:21 Comment(0)
P
1

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.

Puritanical answered 20/1, 2011 at 3:28 Comment(0)
P
0

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();
Parturient answered 2/4, 2013 at 11:55 Comment(0)
W
0

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

Wheezy answered 6/2, 2018 at 1:32 Comment(1)
This answer suits me best. @Wheezy could you consider adding the link to the official spec docs.oasis-open.org/office/v1.1/OS/OpenDocument-v1.1-html/… to your answer? To be a top notch answer someone could also add a code sample.Phelps

© 2022 - 2024 — McMap. All rights reserved.