Saturday, February 3, 2007

ASP.Net - Export to Excel - Unicode characters are not being displayed correctly

I found this problem when exporting datagrid to excel using .Net Response object.
Quite strange actually, we have no problem in our local (WinXP), but when we deploy to the Server (Win2K), the excel result is not displaying the unicode characters correctly.
It can work after we tried to open the excel result using notepad and then saved it with unicode encoding, notice that previously when we first open the document in excel, the font is Arial, but after saving the file with the encoding, it is using Arial Unicode MS.
After several hours, testing this and that, in the end i found an article for exporting datagrid to excel in CodeProject.
And the reply post in the link just resolved my problem.

Illustration :
When exporting the datagrid to excel, actually all of the things are still in html elements (can try to open the excel file using notepad / text editor). So the content will be <table><tr>.....</tr></table>.

I thought that this encoding problem can be resolved by trying to modify the charset and contentencoding in the response object. But i was wrong :(
From the reply post above, you can see that actually it is very simple thing, just add a head element with

<meta http-equiv=Content-Type content="text/html; charset=utf-8">

before rendering the datagrid.
This way, the output can be intepreted correctly, and the unicode can be displayed correctly.


Anonymous said...

Thank you...

Anonymous said...

thank u too

Anonymous said...

Thank you very much,

İlker Ç.

Anonymous said...

I got also my problem solved.. Thank u so much.

Anonymous said...

I don't know how to thank you..!!!

You saved my day(s) !!!

:-) Cheers & all d best


Anonymous said...

Thanks a million !

Post a Comment