AD

gridview export data to Excel office2007.2010 open garbage

Original code

gvMonograph.DataBind();
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        gvMonograph.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();

Need to change a place that is Response.ContentEncoding = System.Text.Encoding.UTF7;
To Response.ContentEncoding = System.Text.Encoding.UTF8; immediately after the normally open 20072010

After the code change:

gvMonograph.DataBind();
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        gvMonograph.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
标签: contenttype, tw, garbage, export data, content disposition, stringwriter, urlencode, hw, htmltextwriter
分类: DotNet
时间: 2010-12-11

相关文章

  1. jqgrid demo Export Data to Excel

    Export Data to Excel jqgrid with functional demo: http://www.trirand.net/demophp.aspx
  2. How to Export Data to Excel from an ASP.NET Application + Avoid the File Format

    Original link: http://blogs.msdn.com/b/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-n ...
  3. sqlserver using BCP to export data to EXCEL, CSV file

    Whether using a batch, or. Net programs, stored procedures can use this command. When we encounter a large num ...
  4. Export data to Excel to DataGridView

    /// <summary> /// Export data to the DataGridView Excel( When the page ) /// </summary> /// <pa ...
  5. PL / SQL Developer tool to export data to excel, import excel data into a table

    Use PL / SQL Developer tool. Export: 1 execute a select statement to query the need to export data. 2. Right i ...
  6. Using SQL * Loader to export data to Excel Oracle

    Achieve the purpose: to oracle database, insert data in excel file to achieve these steps: 1, open MicroSoft E ...
  7. Will export data to excel flex page

    [Size = medium] to achieve the flex in this case the data using as3xls-1 [1] .0. Swc export to excel file flas ...
  8. mysql export data to excel

    1 export select * from test outfile '/ tmp / reg.xls' Will export the data in the / tmp directory 2. Transcodi ...
  9. SQL SERVER, and import and export data from EXCEL

    1. In SQL SERVER query Excel Data : -- ====================================================== SELECT * FROM Op ...
  10. javascript to export data to excel in the table (to support export form lines)

    <HTML> <HEAD> <META http-equiv=Content-Type content="text/html; charset=utf-8"> &l ...
  11. Export Data to Excel JS

    function method2 (tableid) / / read the table to EXCEL in each unit ( var curTbl = document.getElementById (ta ...
  12. Flex page will export data to excel

    Operating environment is the RIA <?xml version="1.0" encoding="utf-8"?> <mx:Windo ...
  13. POI Export Data to Excel

    import java.io.FileOutputStream; import java.util.Iterator; import java.util.List; import java.util.Map; impor ...
  14. datagrid export data to Excel

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.ad ...
  15. Export data to Excel in Java example-poi

    package biz; import java.io.FileOutputStream; import java.io.IOException; import java.util.Date; import org.ap ...
  16. How to use PLSQL Developer import and export data from oracle database

    How to use PLSQL Developer import and export data from oracle database With pl / sql developer export table da ...
  17. GridView Export Excel

    1, first set the aspx page EnableEventValidation = "false" as follows: <%@ Page Language="C# ...
  18. GridView Export Excel caveats

    The data in the GridView export to Excel, and then selected by the user to save or open the print, although th ...
  19. 2010.03.01 - html export to word excel documents

    2010.03.01 - html export to word excel documents html <body> <BR> <table id = "PrintA" ...