Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ExcelFile As String = "C:\ExcelSpreadsheetFile.xlsx"
Dim ExcelConnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ExcelFile & ";Extended Properties=""Excel 12.0;HDR=YES;"""
Dim DataSource As New System.Data.OleDb.OleDbConnection(ExcelConnection)
DataSource.Open()
Dim ExcelTables As New Data.DataTable
ExcelTables = DataSource.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, Nothing)
Dim FirstSheetName = ExcelTables.Rows(0)("TABLE_NAME")
Dim DataAdapter1 As New Data.OleDb.OleDbDataAdapter("Select * from [" & FirstSheetName & "]", ExcelConnection)
Dim DataTable1 As New Data.DataTable
DataAdapter1.Fill(DataTable1)
DataAdapter1.Dispose()
DataSource.Dispose()
GridView1.DataSource = DataTable1
GridView1.DataBind()
End Sub
Tips and tricks for .NET using ASP and VB code.
Load an Excel spreadsheet file into a web page GridView
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment