已有56人关注
gridview
发表在C#图书答疑 2009-06-30
是否精华
版块置顶:
 在将GridView导出EXCEL,打开时,提示不能读取文件
 代码如下:
     Report report = new Report();
        System.Data.DataTable  dt = report.Get_Settlement_Searching_History(fromdate, todate, customer_code, source).Tables[0];
        this.GridView1.DataSource = dt;
        this.GridView1.DataBind();

          Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" +    HttpUtility.UrlEncode("Settlement_Searching_History.xls", System.Text.Encoding.UTF8).ToString());
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;

        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GridView1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.Flush();
        Response.End();
    public override void VerifyRenderingInServerForm(Control control) { }

 希望帮忙解决下。先谢了。
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2009-06-30
沙发
读者朋友:
    您好,运行这个例子后,应该是弹出一个对话框,您需要首先单击“保存”按钮,保存这个excel文件。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照