Hello, there is a problem I'm afraid there is no solution for, but I wish to ask anyway just in case someone knows.
My application downloads a third-party XLS file from the web. I cannot change its format so I have to teach my application to open it as it is.
I'm using OleDb for opening, here's my code:
vb Code:
' If XLSFile = "" Then Exit Sub Dim sExcelConn As String = _ String.Format( _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";", XLSFile) Dim conn As New OleDbConnection(sExcelConn) Dim ds As New DataSet() conn.Open() Dim dtschema As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) Dim tablename As String = "" If dtschema.Rows.Count > 0 Then tablename = dtschema.Rows(0).Item("TABLE_NAME").ToString() Else Exit Sub End If Dim cmd As New OleDbCommand(String.Format("SELECT * FROM [{0}];", tablename), conn) Dim dtData As New DataTable Dim da As New OleDbDataAdapter(cmd) da.Fill(dtData)
Everything works fine except one thing.
The headers of the table I'm trying to get are on the second row, not on the first one. It looks like this:
Now, when I get that table the headers are treated as data while the table title from the first row is considered a header. Is there a workaround or I just have to live with it?Code:| A | B | C | D | ... ------|---------+---------+---------+---------+ 1|This is a main table title which spans the whole table ------|---------+---------+---------+---------+ 2| Header1 | Header2 | Header3 | Header4 | ... ------|---------+---------+---------+---------+ 3| Data | Data | Data | Data | ------|---------+---------+---------+---------+ ...




Reply With Quote