asp.net 导入excel文件

分享到: 更多

方法:

1、先把excel文件上传到服务器

2、把上传的excel文件作为数据源读取其中的内容:

Dim ConnStr As String = “Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =” + strFileName + “;Extended Properties=’Excel 8.0;HDR=False;IMEX=1′”
Dim Conn As New OleDbConnection
Dim Com As New OleDbCommand
Dim Rs As OleDbDataReader
Dim strSql As String = “select * from [Sheet1$]”
Conn.ConnectionString = ConnStr
Conn.Open()
Com.Connection = Conn
Com.CommandText = strSql
Rs = Com.ExecuteReader
Do While Rs.Read
Rs(0).ToString()  ‘此处处理读出的每行数据,注意数据是从excel文件的第二行开始读的

Loop
File.Delete(strFileName)
Conn.Close()

Leave a Reply

Google AdWords