English 中文(简体)
Is there a way to create/read a LibreOffice Spreadsheet just like MS Office Excel with C#?
原标题:

In a program that creates an excel file, i wonder if i could give the chance to the users that don t have MS Office to create an .xls file with only LibreOffice installed. What should i use instead of "using Excel = Microsoft.office.interlope.excel;" and the rest of the commands ? TnX!

最佳回答

LibreOffice uses the ODF (Open Document Format). ODF is not a hard format to grasp because all it basically is is a collection of XML files that are zipped into one file, called an ODF file. You can read here on how to read and save ODF files. Also, you can check here for a real example in C#

问题回答

If you had installed LibreOffice look for cli_basetypes.dll, cli_cppuhelper.dll, cli_oootypes.dll, cli_uno.dll, cli_ure.dll, cli_uretypes.dll then add references to your project, it must work for you, i also installed "Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint File Formats" and "Microsoft Access Database Engine 2010 Redistributable" (to get ACE.OLEDB.12.O connection without complete Office installation). This is a part of VB Sample in which i got connection to oledb to create some queries.

    OpenFileDialog.Filter = "Spreadsheets (*.xls*)|*.xls*"
    OpenFileDialog.Multiselect = False
    Try
        If (OpenFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
            objOffice = CreateObject("com.sun.star.ServiceManager")  preparar instancia libreOffice (prepare libreOffice instance)
            instOffice = objOffice.createInstance("com.sun.star.frame.Desktop")
            Dim obj(-1) As Object
            Dim myDoc = instOffice.loadComponentFromURL("file:///" & OpenFileDialog.FileName.Replace("", "/"), "_default", 0, obj)
            Dim hojas = myDoc.getSheets().getElementNames()  Obtener nombres de las hojas de calculo (get Spreadsheet names)
            System.Threading.Thread.Sleep(1000)  Esperar a que termine la instancia Office (await libreOffice thread)
            myDoc.Close(True)

            Dim MyConnection As System.Data.OleDb.OleDbConnection  Preparar conexión para realizar consulta tipo sql (preparing connection)
            Dim DtSet As System.Data.DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

            If OpenFileDialog.FileName.ToUpper.Contains(".XLSX") Then
                MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & OpenFileDialog.FileName & " ;Extended Properties= Excel 12.0 Xml;HDR=YES;IMEX=1; ")
            Else
                MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & OpenFileDialog.FileName & " ;Extended Properties= Excel 12.0;HDR=YES;IMEX=1 ")
            End If




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签