17-11-20 01:20 PM
Hello,
I have a question regarding the following table:
Name |
Number |
Hours |
Date |
Approve? (Y/N) |
Maria |
123 |
8 |
11/16/2020 |
Y |
Ana |
456 |
10 |
11/16/2020 |
N |
I read this table from the HTML body of an Email, so I have to work with the HTML format of the table.
I want to extract the value of the last column with "Y" or "N". Also, I want to know for which name is approved or not.
Any ideas on how should I do that?
Thanks a lot,
18-11-20 10:25 AM
18-11-20 02:37 PM
18-11-20 04:31 PM
18-11-20 05:54 PM
// Ref: HtmlAgilityPack.dll, System.Core.dll
// NS: HtmlAgilityPack, System.Linq
// In:html (Text), Out:dt (Collection)
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
dt = new DataTable();
HtmlNode table = doc.DocumentNode.SelectNodes("//table")[0]; // Pick first table
HtmlNodeCollection headers = table.SelectNodes("//tr/th"); // Headers
// Columns
foreach (HtmlNode header in headers)
dt.Columns.Add(header.InnerText, typeof(string));
// Rows
foreach (HtmlNode row in table.SelectNodes("//tr"))
dt.Rows.Add(row.Descendants("td").Select(td => td.InnerText).ToArray());
Assuming table has headers and no colspans, this should work with any number of columns/rows.
18-11-20 09:38 PM
18-11-20 10:05 PM
18-11-20 11:04 PM
02-12-20 02:27 PM
03-12-20 02:01 PM