启动 openoffice calc 并打开 csv 文件

发布于 2024-10-29 21:55:18 字数 233 浏览 0 评论 0原文

我的 .NET C# 应用程序中有一个函数,可以将数据从 DataGridView 导出到 CSV 文件,并使用 Excel 打开该文件。

有没有办法使用 OpenOffice Calc 来做到这一点? IE 如何从我的代码启动 Calc 应用程序并指向我制作的 CSV 文件?

I have a function in my .NET C# application which export data from DataGridView to CSV file, and opens the file with Excel.

Is there a way to do this using OpenOffice Calc instead?
I.e.
How can I start Calc application from my code and pointing to the CSV file I have made?

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

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

发布评论

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

评论(2

鱼窥荷 2024-11-05 21:55:18

我为您找到了一篇文章

http://www.opendocument4all.com/download/OpenOffice.net .pdf

这段代码给了你一个想法;

XStorable2 xs = (XStorable2)mxDocument;

xs.storeToURL("file:///C:/oo.xls", new unoidl.com.sun.star.beans.PropertyValue[0]);

我还为您找到了此链接

创建 OpenOffice Writer使用 C# 编写文档

创建 OpenOffice Calc使用 C# 的文档

C#到 OpenOffice Calc

编辑

using System;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.text;
using unoidl.com.sun.star.beans;

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 = "This will be my first paragraph.\n\r";
docText += "This will be my second paragraph.\n\r";

And then this is written to the body of the document:
((XTextDocument)oDoc).getText().setString(docText);

string fileName = @"C:\Reports\test.odt";
fileName = "file:///" + fileName.Replace(@"\", "/");

And then the file is saved to disk:
((XStorable)oDoc).storeAsURL(fileName, propVals);

((Xcomponent)oDoc).dispose();

I found an article for you

http://www.opendocument4all.com/download/OpenOffice.net.pdf

And this code gives you an idea;

XStorable2 xs = (XStorable2)mxDocument;

xs.storeToURL("file:///C:/oo.xls", new unoidl.com.sun.star.beans.PropertyValue[0]);

I also found this links for you

Creating an OpenOffice Writer Document with C#

Creating an OpenOffice Calc Document with C#

C# to OpenOffice Calc

EDIT:

using System;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.bridge;
using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.text;
using unoidl.com.sun.star.beans;

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 = "This will be my first paragraph.\n\r";
docText += "This will be my second paragraph.\n\r";

And then this is written to the body of the document:
((XTextDocument)oDoc).getText().setString(docText);

string fileName = @"C:\Reports\test.odt";
fileName = "file:///" + fileName.Replace(@"\", "/");

And then the file is saved to disk:
((XStorable)oDoc).storeAsURL(fileName, propVals);

((Xcomponent)oDoc).dispose();
雪花飘飘的天空 2024-11-05 21:55:18

Soner Gonul 向您解释了如何导出为 CSV

要使用 OpenOffice Calc 打开文件,只需获取 OpenOffice Calc 可执行文件的路径,然后使用参数中的文件路径启动它

Process.Start("pathToYourOpenOfficeCalc.exe","pathToYourCSVFile");

即可。

Soner Gonul explained you how to export to CSV.

To open the file with OpenOffice Calc just get the path of the OpenOffice Calc executable and launch it with your file path in the arguments

Process.Start("pathToYourOpenOfficeCalc.exe","pathToYourCSVFile");

That's all.

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