2011-04-01 26 views
2

J'ai une fonction dans mon application .NET C# qui exporte les données du fichier DataGridView vers CSV, et ouvre le fichier avec Excel.Démarrer openoffice calc et ouvrir le fichier csv

Existe-t-il un moyen de le faire en utilisant OpenOffice Calc à la place? I.e. Comment puis-je lancer l'application Calc à partir de mon code et en pointant vers le fichier CSV que j'ai créé?

Répondre

-1

J'ai trouvé un article pour vous

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

Et ce code vous donne une idée;

XStorable2 xs = (XStorable2)mxDocument; 

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

Je trouve aussi ce lien pour vous

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

Soner Gonul vous a expliqué comment exporter vers CSV.

Pour ouvrir le fichier avec OpenOffice Calc simplement obtenir le chemin de l'exécutable OpenOffice Calc et lancez votre chemin de fichier dans les arguments

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

C'est tout.

Questions connexes