将dataTable转成表格

//内容很好理解,只需当成Table来拼字符串即可
private string getExcelContent(DataTable dt)
{
StringBuilder sb = new StringBuilder();

sb.Append("<table>");
sb.Append("<thead><tr>");
for (int m = 0; m < dt.Columns.Count; m++)
{
sb.Append("<th>" + dt.Columns[m] + "</th>");
}
sb.Append("</tr></thead>");
sb.Append("<tbody>");

for (int i = 0; i < dt.Rows.Count; i++)
{
sb.Append("<tr>");

for (int j = 0; j < dt.Columns.Count; j++)
{
sb.Append("<td>" + dt.Rows[i][dt.Columns[j]] + "</td>");
}
sb.Append("</tr>");
}

sb.Append("</tbody></table>");
return sb.ToString();
}

posted @ 2014-02-21 11:23  关关雎鸠,在广州  阅读(327)  评论(0编辑  收藏  举报