如何使用 C#.NET 创建 .odt 文件?

发布于 2024-07-07 20:45:13 字数 259 浏览 6 评论 0原文

注意:我发现了“Creating a Word Doc in C#.NET”,但这不是我想要的。

你知道如何创建 .odt 来从 C# .NET 创建文件吗?
OpenOffice.org 库是否有 .NET 组件或包装器来执行此操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

墨小沫ゞ 2024-07-14 20:45:13

看看 AODL(参见 http://odftoolkit.org/projects/odftoolkit/pages/AODL )。

  • 完全托管的.NET 1.1(因此它在MS.Net和Mono上运行)
  • 支持文本和电子表格文档
  • 创建、读取、编辑、保存文档
  • ...

由kame编辑:
新链接
AODL-Wiki

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

烟花易冷人易散 2024-07-14 20:45:13

您可以查看 OASIS 标准网站,了解有关 ODT 标准的信息。 据我所知,他们使用基于 XML 的标准,并且有可用于文档标准的 XSD,因此您可以将其与您自己的代码结合使用,以正确的格式构建文档文件。

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.

情独悲 2024-07-14 20:45:13

我昨天在寻找创建电子表格的方法时发现了这个,看起来创建编写器文件非常相似:
http://www.suite101.com/content /creating-an-openoffice-calc-document-with-c-a124112,不要忘记先安装 Oracle 的 Open Office SDK。

不幸的是,我还没有找到一种在不打开文件的情况下创建文件的方法。

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.

萌酱 2024-07-14 20:45:13

代码如下所示:

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

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();
红尘作伴 2024-07-14 20:45:13

OpenOffice 文档 (odt) 是 ZIP 文件。 您可以解压现有文件,通过代码修改 content.xml 文件,然后使用 System.IO.Compression 中的 ZipFile 类再次获取 zip 文件。 开放办公规范

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文