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 29
|
private static string ConvertCsvToHtml(string csvText) { 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()); }
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; }
|
近期评论