Convert DataTable to Html format

Need to generate summary report:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public string GenerateSummarylHtmlReport(DataTable table)
{

int rowCount = table.Rows.Count;
int colCount = table.Columns.Count;
string summaryReport = " <html>";
summaryReport += "<h1 style='text-align:center'> Test Report</h1>";
summaryReport += "<body>";
summaryReport += "<table border = '1' cellspacing='0' cellpadding='2' width='100%'>";
summaryReport += "<tr style='background-color:#cccccc'><th>Select</th><th>Page Name</th><th>Repository</th><th>Status</th>" +
"<th>Detail</th><th>Start Time</th><th>End Time</th></tr>";
for (int i = 0; i < rowCount; i++)
{
summaryReport += "<tr>";
for (int j = 0; j < colCount; j++)
{
if (table.Rows[i][j].ToString() == "Failed")
{
summaryReport += "<td style='background-color:red'>" + table.Rows[i][j] + "</td>";
}
else if (table.Rows[i][j].ToString().IndexOf("Passed:") != -1)
{
string pageName = table.Rows[i][1].ToString();
string reportTime = table.Rows[i][5].ToString();
string startDate = reportTime.Split('-')[0].Trim();
string startTime = reportTime.Split('-')[1].Trim();
string formatStartDate = startDate.Split('/')[2] + startDate.Split('/')[0] + startDate.Split('/')[1];
string formatStartTime = startTime.Split(':')[0] + startTime.Split(':')[1] + startTime.Split(':')[2];
summaryReport += "<td><a href='" + formatStartDate + "/" + pageName + formatStartTime + ".html'>" + table.Rows[i][j] + "</td>";
}
else
{
summaryReport += "<td>" + table.Rows[i][j] + "</td>";
}
}
summaryReport += "</tr>";
}
summaryReport += "</table>";
summaryReport += "</body>";
summaryReport += "</html>";
return summaryReport;
}

唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!