//内容很好领略,只需当成Table来拼字符串即可
private string getExcelContent()
{
StringBuilder sb = new StringBuilder();
sb.Append("<table borderColor='black' >");
sb.Append("<thead><tr><th colSpan='2' bgColor='#ccfefe'>标题</th></tr>");
sb.Append("<tr><th bgColor='#ccfefe'>号码</th><th bgColor='#ccfefe'>名字</th></tr></thead>");
sb.Append("<tbody>");
sb.Append("<tr><td bgcolor='#FF99CC'></td><td></td></tr>");
sb.Append("<tr><td></td><td bgcolor='lightskyblue'></td></tr>");
sb.Append("</tbody></table>");
return sb.ToString();
}
private void hidExport_Click(object sender, System.EventArgs e)
{
string content = getExcelContent();
string css = ".firstTR td{color:blue;width:100px;}.secondTR td{color:blue;width:100px;}";
string filename = "Test.xls";
CommonTool.ExportToExcel(filename, content ,css);
}
东西类CommonTool
复制代码 代码如下: