excel导出格式问题
protected void btnexcel_Click(object sender, EventArgs e)
{
StringWriter sw = new StringWriter();
sw.WriteLine("Id\t报装编号\t业主姓名\t性别\t出生年月\t联系电话\tQQ\tEmail\t微信\t报修地址\t建筑面积\t户型\t预约时间\t你知道\t能实现什么功能\t如何知道\t你最看以下哪方面内容\t最吸引你的地方在哪里");
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["hkdconstr"].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("select id , seokey , partname1 ,tel1 ,fax1 ,coad1 ,email1 ,address1 ,partname2 ,tel2 ,fax2 ,coad2 ,email2 ,address2 ,partname3 ,tel3 ,fax3 ,coad3 from lx1", conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
sw.WriteLine(reader["id"].ToString() + "\t" + reader["seokey"].ToString() + "\t" + reader["partname1"].ToString() + "\t" + reader["tel1"].ToString() + "\t" + reader["fax1"].ToString() + "\t" + reader["coad1"].ToString() + "\t"+
reader["email1"].ToString() + "\t" + reader["address1"].ToString() + "\t" + reader["partname2"].ToString() + "\t" + reader["tel2"].ToString() + "\t" + reader["fax2"].ToString() + "\t" + reader["coad2"].ToString() + "\t"+
reader["email2"].ToString() + "\t" + reader["address2"].ToString() + "\t" + reader["partname3"].ToString() + "\t" + reader["tel3"].ToString() + "\t" + reader["fax3"].ToString() + "\t" + reader["coad3"].ToString() + "\t"
);
}
reader.Close();
conn.Close();
Response.Charset = "GB2312";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("客户信息"+DAL.common.GetTimeG(DateTime.Now), System.Text.Encoding.UTF8) + "test.xls");//这句话是保存的Excel文件名
Response.Write("<html><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8"><title>显示详细信息</title></head><body>");
Response.Write(sw.ToString());
Response.Write("</body></html>");
Response.End();
sw.Close();
}
protected void btnexcel_Click(object sender, EventArgs e)
{
StringWriter sw = new StringWriter();
sw.WriteLine("Id\t报装编号\t业主姓名\t性别\t出生年月\t联系电话\tQQ\tEmail\t微信\t报修地址\t建筑面积\t户型\t预约时间\t你知道\t能实现什么功能\t如何知道\t你最看以下哪方面内容\t最吸引你的地方在哪里");
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["hkdconstr"].ConnectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("select id , seokey , partname1 ,tel1 ,fax1 ,coad1 ,email1 ,address1 ,partname2 ,tel2 ,fax2 ,coad2 ,email2 ,address2 ,partname3 ,tel3 ,fax3 ,coad3 from lx1", conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
sw.WriteLine(reader["id"].ToString() + "\t" + reader["seokey"].ToString() + "\t" + reader["partname1"].ToString() + "\t" + reader["tel1"].ToString() + "\t" + reader["fax1"].ToString() + "\t" + reader["coad1"].ToString() + "\t"+
reader["email1"].ToString() + "\t" + reader["address1"].ToString() + "\t" + reader["partname2"].ToString() + "\t" + reader["tel2"].ToString() + "\t" + reader["fax2"].ToString() + "\t" + reader["coad2"].ToString() + "\t"+
reader["email2"].ToString() + "\t" + reader["address2"].ToString() + "\t" + reader["partname3"].ToString() + "\t" + reader["tel3"].ToString() + "\t" + reader["fax3"].ToString() + "\t" + reader["coad3"].ToString() + "\t"
);
}
reader.Close();
conn.Close();
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.Charset = "GB2312";
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("客户信息"+DAL.common.GetTimeG(DateTime.Now), System.Text.Encoding.UTF8) + "test.xls");//这句话是保存的Excel文件名
Response.Write(sw.ToString());
Response.End();
sw.Close();
}