To gain access to the Microsoft Excel file you can simply put all 'object data.OledDbConnection
Extended Properties = Excel 8.0;"
' Connect to the source file
Dim conn As New
System.Data.OleDb.OleDbConnection (strConn)Dim myData As New Data.OleDb.OleDbDataAdapter ("SELECT * FROM [sheet1 $]", strConn
And to read the contents:
)
myData.Fill (myDataSet)
And if now we wanted to see the contents in a gridview:DefaultView GridView1.DataBind ()
GridView1.DataSource myDataset.Tables = (0).
The real problem is that not always know the exact structure of the Excel files, especially those sheets (worksheets) are there and their names , which is important to perform a SELECT data.
One approach would be to use objects. Net framework to access the COM office solution disadvantage, forcing them to have Office installed on the machine, and if it is a web server, it could be a serious problem.
most effective approach is the use of the potential for analysis of the structure of the database OledDBConnection through GetOleDbSchemaTable method.
In particular, after opening the connection to the excel file: Dim
schemaTable As Data.DataTable
conn.Open () = schemaTable
conn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables,
New Object () { Nothing, Nothing, Nothing, Nothing})
conn.Close ()
row! TABLE_TYPE.ToString = "TABLE" Then
and then analyzing the pattern:
Dim sheet As New Generic.List (Of String) For Each row As DataRow
In SchemaTable.Rows If
fogli.Add (row! TABLE_NAME.ToString ())
End If Next
is obtained the list of pages.
Main topic, I suggest: How To Retrieve Schema Information by Using GetOleDbSchemaTable and Visual Basic. NET http://support.microsoft.com/kb/309488/en-us
0 comments:
Post a Comment