拼接的字符串导入EXCEL
StringBuilder sb = new StringBuilder();
sb.AppendLine("<table><tr><th>序号</th><th>批单号</th><th>保单号</th><th>被保险人</th><th>保全项目</th><th>退费金额</th><th>保全操作日期</th><th>经办人</th></tr>");
int i = 1;
string str = "abc";
string str1 = "wanglei";
string str2 = "aaa";
string time1 = DateTime.Now.ToString();
sb.AppendLine("<tr><td>1</td><td style=\"vnd.ms-excel.numberformat:@\">" + 243123 + "</td><td style=\"vnd.ms-excel.numberformat:@\">" + str + "</td><td>" + str1 + "</td><td>" + str2 + "</td><td>" + "</td><td>" + time1 + "</td><td>" + str + "</td></tr>");
//foreach (BillChange change in list)
//{
// sb.AppendLine("<tr><td>" + (i++).ToString() + "</td><td style=\"vnd.ms-excel.numberformat:@\">" + change.ChangeBillCode + "</td><td style=\"vnd.ms-excel.numberformat:@\">" + change.BillCode + "</td><td>" + change.BillHolder + "</td><td>" + GetChangeTypeString(change.ChangeType) + "</td><td>" + (change.ReturnFee > 0 ? change.ReturnFee.ToString() : "") + "</td><td>" + change.CreateDatetime.ToString("yyyy-MM-dd") + "</td><td>" + change.CreatorName + "</td></tr>");
//}
sb.Insert(0, "<html><head><meta content='text/html; charset=utf-8' http-equiv='content-type' /></head><body><table border=1>");
sb.AppendLine("</table></body></html>");
Response.Clear();
Response.Buffer = true;
Response.Charset = "UTF-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + Server.UrlEncode("保单变更信息.xls") + "\"");
Response.ContentEncoding = Encoding.UTF8;
Response.ContentType = "application/ms-excel";
Response.Write(sb.ToString());
Response.End();
摘自 wanglei_smartfish的专栏
补充:Web开发 , ASP.Net ,