Exporting to Excel with Chinese Characters

Discussion in 'ASP .Net Datagrid Control' started by tarunbajaj, Oct 15, 2005.

  1. tarunbajaj

    tarunbajaj Guest

    Hello all,
    I am using the code below the DataGrid to Excel but my Chinese
    characters are not converted most of the time.
    The data otherwise display the chars correctly in chinese.
    I am not able to find a concrete solution for this.
    This code works alright with English
    Thanks for help
    private void ShowReport( DataTable pResult )
    {
    dgResult.DataSource = pResult;
    dgResult.DataBind();


    //create the filename
    string strName = REPORT_FILENAME;
    strName = strName +
    Convert.ToString(DateTime.Now.ToShortDateString());
    strName = strName.Replace('/', '_');
    strName = strName + ".xls";
    //strName = strName + ".csv";

    Response.Clear();
    Response.Buffer= true;
    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", "attachment;filename=" +
    strName);
    Response.Charset = "UTF-8";
    this.EnableViewState = true;
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
    System.Web.UI.HtmlTextWriter(oStringWriter);

    dgResult.RenderControl(oHtmlTextWriter);
    Response.Write(oStringWriter.ToString());
    Response.End();

    } //end of ShowReport()
     
    tarunbajaj, Oct 15, 2005
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.