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 = "拜访时间\t" +"机构名\t" +"所在地\t" + "客户类别\t" +"销售方式\t" +"拜访方式\t" + "销售员\t"
+"是否集体培训\t" + "拜访人\t" + "撰写人\t" +
"最后修改时间\t";
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);
//在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
line = rows.ToString() + "\n" + DealWithValue(dr["bfqssj"]).ToString() + "\t"
+
DealWithValue(dr["org_name"]).ToString() + "\t"
+
DealWithValue(dr["org_area"]).ToString() + "\t"
+
DealWithValue(dr["khlb"]).ToString() + "\t"
+
DealWithValue(dr["sale_process"]).ToString() + "\t"
+
DealWithValue(dr["bffs"]).ToString() + "\t"
+
DealWithValue(dr["saler"]).ToString() + "\t"
+
DealWithValue(dr["ass_saler"]).ToString() + "\t"
+
DealWithValue(dr["is_jtpx"]).ToString() + "\t"
+
DealWithValue(dr["unames"]).ToString() + "\t"
+
DealWithValue(dr["operater"]).ToString() + "\t"
+
DealWithValue(dr["op_date"]).ToString() + "\t" +
"\n";
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();
}
原文地址:http://www.cnblogs.com/liupengfei19940119/p/3755712.html