How to read Excel in C#?

  • Thread starter Thread starter davidw
  • Start date Start date
D

davidw

Hi,

I read some articles about handle Excel in C#, they all need import Excel
library. That means you need install Excel on that machine. I am wonderring
SQL 2000 handle Excel, you can import Excel file in SQL 2000 which doesn't
require you install Excel. How could I do the same thing with C#?

thanks!
 
First thing you will always need reference of "Excel 10 Object Library
" to do excel manipulation ( until you want to write your own excel
parser ). If you are not sure that your clients will have excel on
there machine send it to server ( if you are using aspx you always do
that) and parse it on the server. Now you will only need to install
excel in one place thats on the server.

-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/
 
First thing you will always need reference of "Excel 10 Object Library
" to do excel manipulation ( until you want to write your own excel
parser ). If you are not sure that your clients will have excel on
there machine send it to server ( if you are using aspx you always do
that) and parse it on the server. Now you will only need to install
excel in one place thats on the server.

Not a really good idea apparently:
http://support.microsoft.com/default.aspx?scid=kb;en-us;257757

If you need to parse Excel files (and any MS Office files) without having
Office installed, you can use a third party component such as the Aspose
ones http://www.aspose.com/default.aspx
 
¤ Hi,
¤
¤ I read some articles about handle Excel in C#, they all need import Excel
¤ library. That means you need install Excel on that machine. I am wonderring
¤ SQL 2000 handle Excel, you can import Excel file in SQL 2000 which doesn't
¤ require you install Excel. How could I do the same thing with C#?

You don't need the Excel object library, you can use ADO.NET and SQL:

Function ExportExcelToSQLServer() As Boolean

Dim ExcelConnection As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "E:\My
Documents\Book5.xls" & ";" & _
"Extended Properties=""Excel
8.0;HDR=No""")

ExcelConnection.Open()

'Existing table
Dim ExcelCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [ODBC;Driver={SQL
Server};Server=(local);Database=Northwind;Trusted_Connection=yes].[Orders2] SELECT * FROM
[Orders$];", ExcelConnection)
'New table
'Dim ExcelCommand As New System.Data.OleDb.OleDbCommand("SELECT INTO [ODBC;Driver={SQL
Server};Server=(local);Database=Northwind;Trusted_Connection=yes].[Orders2] FROM [Orders$];",
ExcelConnection)

ExcelCommand.ExecuteNonQuery()
ExcelConnection.Close()

End Function


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top