将行转换为列字符串生成器
本文关键字:字符串 转换 | 更新日期: 2023-09-27 18:34:57
我有一个表格要包含在邮件中,如下所示:(我从视图(.cshtml(获取数据(
public ActionResult SendForApproveTimesheet(List<TimesheetMatrix> timesheetmatrixList) {
int n = 1;
timsheetMail = timsheetMail + " <table style='"border-collapse:collapse; text-align:center;'" border='"1'"><tr><td> Date </td><td> Working Hours </td><td> Task </td><td>Comments</td></tr>";
foreach (TimesheetMatrix matrix in timesheetmatrixList) {
if ((timesheetData.Hours != Convert.ToDecimal(0.00)) && (timesheetData.Hours.HasValue == true)) {
timsheetMail = timsheetMail + " <tr><td> " + timesheetData.Date.ToString("dd/MM/yyyy") + "</td><td>" + timesheetData.Hours + "</td><td>" + task + "</td><td>" + timesheetData.Notes + "</td></tr>";
}
n++;
}
我已将其包含在邮件中,如下所示:
mailObj.Body = "Emp Name : " + EmpName + "<br /><br >" + Environment.NewLine + timsheetMail;
现在它包含在邮件中,如下所示:
Date Working Hrs Task Comments
08-02-2016 8 Testing whole application testd
09-02-2016 8 Development Client Requirments
10-02-2016 8 Installation Install the app
11-02-2016 8 Design New design
12-02-2016 8 DB db update
但我想将其更改为以下内容:
08-02-2016 09-02-2016 10-02-2016 11-02-2016 12-02-2016
Testing 8
Development 8
Installation 8
Design 8
DB 8
那是使用枢轴更改我的表。我该怎么做..谁能帮我做到这一点..提前谢谢....
我不确定,但您应该尝试以下代码,我认为它应该对您想要的需求有用。
StringBuilder output = new StringBuilder();
foreach (DataRow rows in results.Tables[0].Rows)
{
foreach (DataColumn col in results.Tables[0].Columns)
{
output.AppendFormat("{0} ", rows[col]);
}
output.AppendLine();
}