if (excel.Checked)
{
ToExcel(dt,"id/t山东/t济南");
}
public void ToExcel(DataTable dt, string colName)
{
StringWriter sw=new StringWriter();
sw.Write(colName);//
foreach(DataRow dr in dt.Rows)
{
sw.WriteLine("");
for(int i = 0; i<dt.Columns.Count; i++)
{
sw.Write(dr[i].ToString().Replace("/n","") + "/t");
}
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=test.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
}