.NET C# アプリケーションに、データDataGridView
をCSV
ファイルにエクスポートする関数があり、.NET でファイルを開きますExcel
。
OpenOffice Calc
代わりにこれを使用する方法はありますか?つまり、コードからアプリケーションを起動し、作成したファイルをCalc
指すにはどうすればよいですか?CSV
.NET C# アプリケーションに、データDataGridView
をCSV
ファイルにエクスポートする関数があり、.NET でファイルを開きますExcel
。
OpenOffice Calc
代わりにこれを使用する方法はありますか?つまり、コードからアプリケーションを起動し、作成したファイルをCalc
指すにはどうすればよいですか?CSV
Soner Gonulが にエクスポートする方法を説明しましたCSV
。
OpenOffice Calc でファイルを開くには、OpenOffice Calc 実行可能ファイルのパスを取得し、引数にファイル パスを指定して起動します。
Process.Start("pathToYourOpenOfficeCalc.exe","pathToYourCSVFile");
それで全部です。
私はあなたのための記事を見つけました
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 ドキュメントを作成する
編集:
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();