2

.NET C# アプリケーションに、データDataGridViewCSVファイルにエクスポートする関数があり、.NET でファイルを開きますExcel

OpenOffice Calc代わりにこれを使用する方法はありますか?つまり、コードからアプリケーションを起動し、作成したファイルをCalc指すにはどうすればよいですか?CSV

4

2 に答える 2

0

Soner Gonulが にエクスポートする方法を説明しましたCSV

OpenOffice Calc でファイルを開くには、OpenOffice Calc 実行可能ファイルのパスを取得し、引数にファイル パスを指定して起動します。

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

それで全部です。

于 2014-05-02T05:06:45.800 に答える
0

私はあなたのための記事を見つけました

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

このリンクも見つけました

C# で OpenOffice Writer ドキュメントを作成する

C# で OpenOffice Calc ドキュメントを作成する

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();
于 2011-04-01T09:20:48.560 に答える