Chrisryn
Chrisryn

Reputation: 1

How to import a .xls file that when opened in notepad is all html? vb.net

I have a .xls file that is downloaded from an asp.net website. I need to import the data from the file into access database using vb.net. If you open the xls file in notepad it is all html. Trying to bring the data in like it is a normal excel file doesn't work.

Upvotes: 0

Views: 685

Answers (2)

Ciarán
Ciarán

Reputation: 3057

You can do this with OLEDB actually, - you specify that it is HTML in the extended properties, E.g.

Dim oleExcelConnection As OleDbConnection

sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Test.xls;Extended Properties=""HTML Import;IMEX=1"""

oleExcelConnection = New OleDbConnection(sConnection)
oleExcelConnection.Open()

...

oleExcelConnection.close()

It's a while since I tried this and it worked okay but I choose to force the files to .xlsx in the final implementation. I can't remember why exactly.

Upvotes: 1

Ceres
Ceres

Reputation: 3648

You may need to open it in excel first and save it in the file format you are trying to use. The file is HTML, it's not in an excel format. The website is using a trick to have the browser open excel with the returned HTML by setting the content-type to application/vnd.ms-excel and the file extension to .xls. The browser will launch excel with the html file in most cases. Excel will see the file is not in the right format but will allow the user to open and import it.

Upvotes: 0

Related Questions