I've been searching in the net with no answers
How do you import a .xls file that is made of <table>,<th>,<tr>,<td>
tags to DataTable?
Asked
Active
Viewed 1,567 times
2
-
I guess you need to parse it and manualy fill DataTable – Stecya May 17 '11 at 11:10
-
Are there any samples, I'm still a beginner at this. Thanks. @Stecya – Corbee May 17 '11 at 11:14
-
1Check this answer - http://stackoverflow.com/questions/655603/html-agility-pack-parsing-tables/655849#655849 – Stecya May 17 '11 at 11:16
-
Where are you getting the XLS file from? You can't, in general, assume all XLS consumers can read HTML (as you're discovering) so you should get whoever's generating it to [generate a real XLS file](http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c) – Rup May 17 '11 at 13:28
2 Answers
1
if the HTML is well formed you can try to load it as XML. Expanding a bit with a very simple example:
System.Xml.Linq.XDocument html = System.Xml.Linq.XDocument.Load (@"[xls doc]");
//this will pull all the Table Headers.
var q = from th in html.Descendants ("th") select (string)th.Value;

Rikal
- 153
- 8
-2
-
He's not asking about reading real Excel files, though - he wants to read a fake XLS file that someone's made by writing an HTML table. – Rup May 17 '11 at 13:55
-
1I doubt that he can use PHP to import anything to ADO.NET DataTable, so -1 – Antonio Bakula May 17 '11 at 14:14