有没有办法用C#创build/读取LibreOffice Spreadsheet就像MS Office Excel?

在创buildexcel文件的程序中,我想知道是否可以给没有MS Office的用户创build一个只安装了LibreOffice的.xls文件。 我应该用什么来代替“使用Excel = Microsoft.office.interlope.excel;” 和其余的命令? TNX!

LibreOffice使用ODF(开放文档格式)。 ODF不是一个难以掌握的格式,因为它基本上是将XML文件压缩成一个文件的集合,称为ODF文件。 你可以在这里阅读如何阅读和保存ODF文件。 另外,你可以在这里查看一个真正的例子在C#

如果你已经安装LibreOffice查找cli_basetypes.dll,cli_cppuhelper.dll,cli_oootypes.dll,cli_uno.dll,cli_ure.dll,cli_uretypes.dll然后添加引用到你的项目,它必须为你工作,我也安装了“Microsoft Office兼容性打包Word,Excel和PowerPoint文件格式“和”Microsoft Access数据库引擎2010可再发行组件“(无需完整的Office安装即可获取ACE.OLEDB.12.O连接)。 这是VB Sample中的一部分,我已经连接到oledb来创build一些查询。

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