Execl导出有有关问题
Execl导出有问题
为什么我的Execl导出的时候数据量大的时候没有问题挺正常的 但是导出一条数据的时候下载下来却是 .aspx后缀的页面
这是怎么回事啊?
------解决方案--------------------
把你的到处代码贴出来或者参看http://blog.ahnw.gov.cn/user1/apeng/archives/2006/10.html
------解决方案--------------------
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";// "UTF-8";//"GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
this.Page.EnableViewState = false;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.ContentType = "application/vnd.ms-excel";//设置输出文件类型为excel文件。
#region 添加表头和数据
string colHeaders = "", ls_item = "";
DataRow[] myRow = dt.Select();//可以类似dt.Select("id>10")之形式达到数据筛选目的
colHeaders += "用户登录名" + "\t";
colHeaders += "姓名" + "\t";
colHeaders += "单位名称" + "\t";
colHeaders += "级别" + "\t";
colHeaders += "手机" + "\t";
colHeaders += "电话" + "\t";
colHeaders += "联系QQ" + "\n";
string bodyData = ExportTable(colHeaders, dt);
Response.Write(bodyData);
Response.End();
public static string ExportTable(string colHeaders, DataTable dt)
{
StringBuilder sb = new StringBuilder();
int count = 0;
sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">");
sb.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">");
////写出列名
sb.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;\">");
foreach (string aStr in colHeaders.Split('\t'))
为什么我的Execl导出的时候数据量大的时候没有问题挺正常的 但是导出一条数据的时候下载下来却是 .aspx后缀的页面
这是怎么回事啊?
------解决方案--------------------
把你的到处代码贴出来或者参看http://blog.ahnw.gov.cn/user1/apeng/archives/2006/10.html
------解决方案--------------------
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";// "UTF-8";//"GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
this.Page.EnableViewState = false;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.ContentType = "application/vnd.ms-excel";//设置输出文件类型为excel文件。
#region 添加表头和数据
string colHeaders = "", ls_item = "";
DataRow[] myRow = dt.Select();//可以类似dt.Select("id>10")之形式达到数据筛选目的
colHeaders += "用户登录名" + "\t";
colHeaders += "姓名" + "\t";
colHeaders += "单位名称" + "\t";
colHeaders += "级别" + "\t";
colHeaders += "手机" + "\t";
colHeaders += "电话" + "\t";
colHeaders += "联系QQ" + "\n";
string bodyData = ExportTable(colHeaders, dt);
Response.Write(bodyData);
Response.End();
public static string ExportTable(string colHeaders, DataTable dt)
{
StringBuilder sb = new StringBuilder();
int count = 0;
sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">");
sb.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">");
////写出列名
sb.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;\">");
foreach (string aStr in colHeaders.Split('\t'))