#region 最简单的导出Excel
publicvoid CreateExcel(DataTable _table, string FileName)
{
//FileName = Server.UrlEncode(FileName);
HttpResponse response = Page.Response;
response.Clear();
response.Buffer =true;
response.Charset ="GB2312";
response.HeaderEncoding = System.Text.Encoding.GetEncoding("GB2312");
response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
response.AddHeader("Content-Disposition", "attachment;filename="+ FileName);
response.AddHeader("Content-Type", "application/octet-stream;charset=GB2312");
response.ContentType ="application/ms-excel";
string ls_item ="";
ls_item ="编号 险种 保单号 手续费 手续费率 佣金 备注 分组序号
";
response.Write(ls_item);
ls_item ="";
int i =1;
foreach (DataRow row in _table.Rows)
{
ls_item = i.ToString() +" "+ row[3] +" "+ row[4] +" "+ row[7] +" "+ row[8] +" "+ row[9] +" "+ row[10] +" "+ i.ToString() +"
";
response.Write(ls_item);
i++;
}
//写缓冲区中的数据到HTTP头文件中
response.Flush();
response.Clear();
response.End();
}
#endregion