private void CreateExcel()
{
string header = string.Empty;
string line = string.Empty;
try
{
dltDataBind();
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=orginfo.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
header = "拜访时间 " +"机构名 " +"所在地 " + "客户类别 " +"销售方式 " +"拜访方式 " + "销售员 " +"是否集体培训 " + "拜访人 " + "撰写人 " + "最后修改时间 ";
Response.Write(header.ToString());
DataTable dt = ds.Tables[0];
int rows = 1;
//逐行处理数据
foreach (DataRow dr in dt.Rows)
{
line = string.Empty;//dt.Rows.IndexOf(dr);
//在当前行中,逐列获得数据,数据之间以 分割,结束时加回车符
line = rows.ToString() + "
" + DealWithValue(dr["bfqssj"]).ToString() + " " +
DealWithValue(dr["org_name"]).ToString() + " " +
DealWithValue(dr["org_area"]).ToString() + " " +
DealWithValue(dr["khlb"]).ToString() + " " +
DealWithValue(dr["sale_process"]).ToString() + " " +
DealWithValue(dr["bffs"]).ToString() + " " +
DealWithValue(dr["saler"]).ToString() + " " +
DealWithValue(dr["ass_saler"]).ToString() + " " +
DealWithValue(dr["is_jtpx"]).ToString() + " " +
DealWithValue(dr["unames"]).ToString() + " " +
DealWithValue(dr["operater"]).ToString() + " " +
DealWithValue(dr["op_date"]).ToString() + " " +
"
";
rows = rows +1;
//当前行数据写入HTTP输出流
Response.Write(line);
}
//写缓冲区中的数据到HTTP头文件中
Response.End();
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
protected void btnoutex_Click1(object sender, EventArgs e)
{
CreateExcel();
}