1

My application is in c# where we are exporting data from data table to excel sheet. i have created unit price column and total price column as below

dtTable.Columns.Add(new DataColumn("Unit Price", typeof(string)));
dtTable.Columns.Add(new DataColumn("Order Total", typeof(string)));

Code of creating excel file

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=PurchaseOrders.xls");
Response.ContentType = "application/vnd.ms-excel";

but when i am exporting datatable to excel sheet currency symbol (£) is getting exported as £

i tried few solution mentioned in few forums for adding encoding as UTF-8 and UTF-32 but it showing £ symbol appended with  char which you can see in below screen.

Exported excel sheet screen shot

Please let me know if you have any solution for this.

Rahul
  • 33
  • 1
  • 6
  • 2
    That looks like you are exporting as UTF-8 but then reading as Latin-1 (or some other 8bit encoding). – Richard Aug 02 '18 at 09:41
  • 1
    Excel has no problem working with € and neither does .NET. I'll bet you *didn't* create an Excel file at all, just a CSV with a fake extension. Where's the code used to create the file? – Panagiotis Kanavos Aug 02 '18 at 09:43
  • BTW creating a *real* `xlsx` file is very easy using a library like EPPlus. In the simplest case you can load your data with a single call to `sheet.LoadFromCollection()` or `sheet.LoadFromDataTable()` and returning the file. There are many questions in SO about EPPlus and how to use it in web applications – Panagiotis Kanavos Aug 02 '18 at 09:45
  • PS: Windows, .NET, ASP.NET and Excel use Unicode natively. `xlsx` files are zipped XML files using Unicode. The result you see is how UTF8 appears when loaded as if it were ASCII text - non-English characters are rendered using two or more bytes in UTF8. This page is encoded using UTF8 and yet, there's nothing wrong with the € symbols – Panagiotis Kanavos Aug 02 '18 at 09:49
  • Not sure if it's a duplicate, but see this question: https://stackoverflow.com/q/11084564/1220550 – Peter B Aug 02 '18 at 10:58
  • Below post resolved my issue and thanks for your response https://stackoverflow.com/questions/1679656/asp-net-excel-export-encoding-problem – Rahul Aug 03 '18 at 13:09

0 Answers0