0
這裏是場景: 我從多個數據庫檢索數據並將其保存在列表和字典中。然後我必須在html文件的主體中創建一個表格,這個表格將作爲一個自動生成的電子郵件,用於每個收件人的表中不同的數據集。我的問題是如何在c sharp文件的主循環中添加單元格到表格中。 這裏的升C代碼片段:將數據從c sharp移動到html表格到電子郵件
foreach(string str in strList)
{
columnOneData = someDict[Key];
columnTwoData = str;
columnThreeData = otherDict[Key];
columnFourData = thirdDict[Key];
}
SmtpClient SmtpServer = new SmtpClient("some.server.com ");
string Body = System.IO.File.ReadAllText(@"C:path\HTMLPage.htm");
Body=Body.Replace("firstColData",columnOneData);
Body=Body.Replace("secondColData",columnTwoData);
Body=Body.Replace("thirdColData",columnThreeData);
Body=Body.Replace("fourthColData",columnFourData);
message.Body = Body;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.Send(message);
這裏就是我要尋找的想法,以保持填充表,而不是隻結束了在HTML文件中
<table border="1" cellpadding="5" cellspacing="5" style="font-family:Calibri;color:Black;">
<tr>
<th>Column One Header</th>
<th>Column Two Header</th>
<th>Column Three Header</th>
<th>Column Four Header</th>
</tr>
<tr>
<td>#firstColDataa#</td>
<td>#secondColData#</td>
<td>#thirdColData#</td>
<td>#fourthColData#</td>
</tr>
</table>
因此,代碼來自上次迭代的數據。
在此先感謝
做什麼? https://github.com/Antaris/RazorEngine效果很好。 – adt 2015-03-25 10:03:31
爲什麼不使用現成的模板解決方案?例如,T4模板集成到Visual Studio和.NET中。只需創建一個運行時模板,您可以非常輕鬆地填寫數據。 – Luaan 2015-03-25 10:03:38
好吧,也許我可以提到我在視覺工作室是個不錯的選擇,我不太明白模板 – PrOjEkTeD 2015-03-25 10:12:32