///
///创建Excel表格///
/// 数据流
/// 文件名称
public static void CreateExcel(DataTable dt, stringFileName)
{
StringBuilder strb= newStringBuilder();
strb.Append("
strb.Append("xmlns:x="urn:schemas-microsoft-com:office:excel"");
strb.Append("xmlns="http://www.w3.org/TR/REC-html40">");
strb.Append("
");strb.Append("
strb.Append(".xl26");
strb.Append("{mso-style-parent:style0;");
strb.Append("font-family:"Times New Roman", serif;");
strb.Append("mso-font-charset:0;");
strb.Append("mso-number-format:"@";}");
strb.Append("");
strb.Append("");
strb.Append("");
strb.Append("");
strb.Append("");
strb.Append("Sheet1 ");
strb.Append("");
strb.Append("285 ");
strb.Append("");
strb.Append("");
strb.Append("");
strb.Append("3 ");
strb.Append("1 ");
strb.Append("");
strb.Append("");
strb.Append("False ");
strb.Append("False ");
strb.Append("False ");
strb.Append("");
strb.Append("");
strb.Append("6750 ");
strb.Append("10620 ");
strb.Append("480 ");
strb.Append("75 ");
strb.Append("False ");
strb.Append("False ");
strb.Append("");
strb.Append("");
strb.Append("");
strb.Append("
int columncount =dt.Columns.Count;for (int columi = 0; columi < columncount; columi++)
{
strb.Append("
" + dt.Columns[columi] + " ");}
strb.Append("
");//写数据for (int i = 0; i < dt.Rows.Count; i++)
{
strb.Append("
");for (int j = 0; j < dt.Columns.Count; j++){
strb.Append("
" + dt.Rows[i][j].ToString() + "");}
strb.Append("
");}
strb.Append("
");strb.Append(" ");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer= true;
HttpContext.Current.Response.Charset= "GB2312";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" +FileName);
HttpContext.Current.Response.ContentEncoding= System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
HttpContext.Current.Response.ContentType= "application/ms-excel";//设置输出文件类型为excel文件。
HttpContext.Current.Response.Write(strb);
HttpContext.Current.Response.End();
}