When design selenium object management tool, need to generate html report from csv file, implement as below: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
29private static string ConvertCsvToHtml(string csvText)
{
//split the CSV, assume no commas or line breaks in text
List<List<string>> splitString = new List<List<string>>();
List<string> lineSplit = csvText.Split('\n').ToList();
foreach (string line in lineSplit)
{
splitString.Add(line.Split(',').ToList());
}
//encode text safely, and create table
string htmlReport = "<html>";
htmlReport += "<h1 style='text-align:center'> Test Report</h1>";
htmlReport += "<body>";
htmlReport += "<table border = '1' cellspacing='0' cellpadding='2' width='100%'>";
foreach(List<string> splitLine in splitString)
{
htmlReport += "<tr>";
foreach(string splitText in splitLine)
{
htmlReport += "<td>" + WebUtility.HtmlEncode(splitText) + "</td>";
}
htmlReport += "</tr>";
}
htmlReport += "</table>";
htmlReport += "</body>";
htmlReport += "</html>";
return htmlReport;
}
Convert csv to Html format
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!
- Post link: http://izheyi.com/2015/11/02/Convert-csv-to-Html-format/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.