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

半世苍凉 提交于 2019-11-29 14:38:25

问题


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?


回答1:


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




回答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.




回答3:


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




回答4:


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.




回答5:


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();



回答6:


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



来源:https://stackoverflow.com/questions/223777/how-to-create-odt-files-with-c-net

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