Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a batch of auto generated CSV files that contain arabic letters with Ansi coded format. I am working to create a tool using c# to convert this batch to excel and it worked, but I couldn't make the excel coding utf-8 to show the arabic letters properly.

This is the code:
string excelFileName = String.Format(destination + @"\{0}{1}", Path.GetFileNameWithoutExtension(fileName), ".xlsx");
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
object misValue = System.Reflection.Missing.Value;

System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

xlApp = new Microsoft.Office.Interop.Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);

xlWorkBook = xlApp.Workbooks.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkBook.SaveAs(excelFileName, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkBook.Close();
Posted
Comments
gggustafson 24-Aug-15 14:41pm    
I didn't know Arabic fit in UTF-8.
Hanan Aqilan 26-Aug-15 0:29am    
Ya Windows Ansi doesn't show Arabic letters, so that is why we need to convert them into UTF-8, but the points that I don't see any option to automate this.
gggustafson 26-Aug-15 12:35pm    
Check out http://stackoverflow.com/questions/15898678/base64-to-utf-8-string-decoding-arabic-text

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900