gridview 导出excel 变成了aspx页面是怎么回事

william_918 2010-07-23 02:33:25
gridview 导出excel 变成了aspx页面是怎么回事 在本地导出就是.xls 的文件, 但是放在服务器下载时就变成了.aspx 页面, 求救了
...全文
613 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
njw1028 2013-01-10
  • 打赏
  • 举报
回复
引用 7 楼 hjywyj 的回复:
http://blog.csdn.net/hongchawendu/article/details/7387535
++
xx小台灯 2013-01-10
  • 打赏
  • 举报
回复
我也碰到了 楼主解决了吗
jdc71264 2012-08-09
  • 打赏
  • 举报
回复
用NPOI吧亲
  • 打赏
  • 举报
回复
http://blog.csdn.net/hongchawendu/article/details/7387535
nierenyi 2012-08-09
  • 打赏
  • 举报
回复
楼主问题解决了吗?分享一下
菜鸟A 2012-05-29
  • 打赏
  • 举报
回复
我的更怪,同样的Buton事件调用方法,TOEXCEL(Gridview1),有的页面可以直接下载的就是EXCEL,有的就是.ASPX,但是如果保存时在迅雷中选使用IE下载后就能下到EXCEL,我都想不通了。
william_918 2010-07-24
  • 打赏
  • 举报
回复
什么意思
wuyq11 2010-07-23
  • 打赏
  • 举报
回复
打开EXCEL模板,遍历赋值到单元格
william_918 2010-07-23
  • 打赏
  • 举报
回复
#region
/// <summary>
/// 根据数据控件,文件类型,文件名称导出文件
/// </summary>
/// <param name="source">数据控件</param>
/// <param name="type">文件类型</param>
/// <param name="fileName">文件名称</param>
public static void Export(Control source, string type, string fileName, Page page)
{
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.Buffer = true;
string fType = type == "excel" ? ".xls" : ".doc";
response.HeaderEncoding = Encoding.UTF8;
response.AppendHeader("Content-Disposition", "attachment;fileName=" + HttpUtility.UrlEncode(fileName + fType, Encoding.UTF8));
response.ContentType = "application/ms-excel";
response.Charset = "GB2312";
response.ContentEncoding = Encoding.UTF8;
StringWriter sWriter = new StringWriter();
HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);
source.EnableViewState = false;
source.RenderControl(hWriter);
response.Write(sWriter);
response.ContentType = "text/html";
page.RegisterStartupScript("onload", "<script language=javascript>window.location=window.location;window.alert();</script>");
response.End();
}
//重写VerifyRenderingInServerForm方法,什么事也不干(也就是阻止系统调用默认的VerifyRenderingInServerForm方法)
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//文本:vnd.ms-excel.numberformat:@
//日期:vnd.ms-excel.numberformat:yyyy/mm/dd
//数字:vnd.ms-excel.numberformat::#,##0.00
//货币:vnd.ms-excel.numberformat¥#,##0.00
//百分比:vnd.ms-excel.numberformat:#0.00%
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//表示对每一行以字符串的形式输出
e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
}
}
#endregion
z273894270 2010-07-23
  • 打赏
  • 举报
回复
可能是代码的问题啊。你吧代码发点出来。让大家给你看下。

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧