Jes Sie

Jes Sie

  • 737
  • 1.2k
  • 284.6k

Language output is not correct when exporting to excel

Sep 3 2017 12:15 AM
Hello good day! I have a webform application and I exported its content to an excel format. The language saved in my SQL Server is Lao script, but when I exported to excel it becomes unreadable. Below is the gridview before exporting to excel.
 
Below is the exported data in excel:
 
below is my code when exporting to excel:
  1. protected void btnExport_Click(object sender, EventArgs e)  
  2.         {  
  3.             Response.ClearContent();  
  4.             Response.AppendHeader("content-disposition""attachment; filename=IssuedTaxInvoices.xls");  
  5.             Response.ContentType = "application/excel";  
  6.   
  7.             StringWriter stringWriter = new StringWriter();  
  8.             Html32TextWriter htmlTextWriter = new Html32TextWriter(stringWriter);  
  9.   
  10.             //Below code will format the color only to the affected area  
  11.             GridView1.HeaderRow.Style.Add("background-color""#FFFFFF");  
  12.   
  13.             foreach (TableCell tableCell in GridView1.HeaderRow.Cells)  
  14.             {  
  15.                 tableCell.Style["background-color"] = "#000084";  
  16.             }  
  17.   
  18.             foreach (GridViewRow gridViewRow in GridView1.Rows)  
  19.             {  
  20.                 gridViewRow.BackColor = System.Drawing.Color.White;  
  21.                 foreach (TableCell gridviewRowTableCell in gridViewRow.Cells)  
  22.                 {  
  23.                     gridviewRowTableCell.Style["background-color"] = "#EEEEEE";  
  24.                 }  
  25.             }  
  26.   
  27.             GridView1.FooterRow.Style.Add("background-color""#FFFFFF");  
  28.   
  29.             foreach (TableCell tableCell in GridView1.FooterRow.Cells)  
  30.             {  
  31.                 tableCell.Style["background-color"] = "#CCCCCC";  
  32.             }  
  33.   
  34.             foreach (GridViewRow gridViewRow in GridView1.Rows)  
  35.             {  
  36.                 gridViewRow.BackColor = System.Drawing.Color.White;  
  37.                 foreach (TableCell gridviewRowTableCell in gridViewRow.Cells)  
  38.                 {  
  39.                     gridviewRowTableCell.Style["background-color"] = "#EEEEEE";  
  40.                 }  
  41.             }  
  42.   
  43.             //formatting of color ends here  
  44.   
  45.             GridView1.RenderControl(htmlTextWriter);  
  46.             Response.Write(stringWriter.ToString());  
  47.             Response.End();  
  48.         }  
 thanks in advance for any help.

Answers (2)