in my .net code i'm using
byte[] bytesToSend = System.Text.Encoding.UTF8.GetBytes(partialtorender);
then m writin it to excel
the text in "Hindi" Language is coming gibberish in generated excel, can you please suggest what to do?
System.IO.MemoryStream memStr = new System.IO.MemoryStream();
memStr.Write(bytesToSend, 0, bytesToSend.Length);
memStr.Position = 0;
FileStreamResult result1 = new FileStreamResult(memStr, "application/ms-excel");
Response.AddHeader("content-disposition", "attachment; filename=" + "newExcelSheet" + ".xls");
return result1;
Try emitting an UTF-8 preamble to indicate the correct encoding to Excel. Also .xls is a proprietary binary format. You cannot just use a string variable as in your code.
Here's an example with a CSV file export:
Your problem could be that the default encoding for XLS files is not UTF-8. Please save the file you got and open it according to this post: Choose an encoding standard when you open a file Does this fix your problem?
I found out the solution after a lot of struggle. If you look at the text of the xls file you will see it's not a well formed html, anyway excel does handle it. But I thought i should let excel know it's utf-8. so i used:
before writing the rest of the stream, and it does work!.