c#导出excel文档,为什么用IE9或360安全浏览器导出的是源文件?谷歌和遨游浏览器正常。 10
导出excel,我用遨游和谷歌浏览器导出是excel文件,没有问题,可是用360安全浏览器和IE9导出,却是这个页面源文件“Default.aspx”?但是导出的“Def...
导出excel,我用遨游和谷歌浏览器导出是excel文件,没有问题,可是用360安全浏览器和IE9导出,却是这个页面源文件“Default.aspx”?但是导出的“Default.aspx”不完全是Visual Studio源文件,绑定了这个表的第一条数据的ID,这是为何呢?小女子不才,请教各位高手,该如何解决?在线等!下面附导出按钮代码
find();
DataSet ds = new DataSet();
ds = conn.DsSql("select field1,field2,field3,field4,field5,field6,field7,field8 from asset..V_Asset where " + Str_Con + Str_conds);
StringWriter sw = new StringWriter();
sw.WriteLine("字段1\t字段2\t字段3\t字段4\t字段5\t字段6\t字段7\t字段8\t");
foreach (DataRow dr in ds.Tables[0].Rows)
{
sw.WriteLine("'" + dr[0].ToString() + "\t" + dr[1].ToString() + "\t" + dr[2].ToString() + "\t" + dr[3].ToString() + "\t" + dr[4].ToString() + "\t" + dr[5].ToString() + "\t" + dr[6].ToString() + "\t"+ dr[7].ToString() + "\t");
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=MyExcel.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End(); 展开
find();
DataSet ds = new DataSet();
ds = conn.DsSql("select field1,field2,field3,field4,field5,field6,field7,field8 from asset..V_Asset where " + Str_Con + Str_conds);
StringWriter sw = new StringWriter();
sw.WriteLine("字段1\t字段2\t字段3\t字段4\t字段5\t字段6\t字段7\t字段8\t");
foreach (DataRow dr in ds.Tables[0].Rows)
{
sw.WriteLine("'" + dr[0].ToString() + "\t" + dr[1].ToString() + "\t" + dr[2].ToString() + "\t" + dr[3].ToString() + "\t" + dr[4].ToString() + "\t" + dr[5].ToString() + "\t" + dr[6].ToString() + "\t"+ dr[7].ToString() + "\t");
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=MyExcel.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End(); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询