We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unable to create excel file with ANSI encoding


I have to create and saving an excel file  in ANSI encoding. I am using below code but it it is still creating file in UTF-8 encoding.

using (ExcelEngine excelEngine = new ExcelEngine())
                    IApplication application = excelEngine.Excel;
                    application.DefaultVersion = ExcelVersion.Xlsx;
                    IWorkbook workbook = application.Workbooks.Create(1);
                    IWorksheet worksheet = workbook.Worksheets[0];
                    worksheet.ImportDataTable(dataTable, true, 1, 1, true);

                   IListObject table = worksheet.ListObjects.Create("WEEKLYDATA", worksheet.UsedRange);

                   table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium14;


                        string fileName = "ReportFile.csv");

                       Stream excelStream = File.Create(fileName);

                       CultureInfo cultureInfo =CultureInfo.CurrentCulture;
                        Encoding encoding= Encoding.GetEncoding(cultureInfo.TextInfo.ANSICodePage);
                        workbook.SaveAs(excelStream, ",", encoding);


Please help.

3 Replies

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team October 18, 2022 08:36 AM

Hi naina,

Greetings from Syncfusion.

Syncfusion XlsIO saves the Excel file with selected encoding. As you have reported that the encoding is set improperly in saved Excel document, kindly let us know how are you checking the encoding of this saved file. This helps us in investigating the query further.



NR naina ramnani October 18, 2022 08:44 AM

Hi Keerthi, I am opening file in notepad and see the encoding over there. I have set the default encoding for my notepad as ANSI in registry editor

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team October 19, 2022 06:25 AM

Hi naina,

Thanks for the update.

There is an option called Apply to opened ANSI files under UTF-8 encoding in notepad settings. If this option is enabled, even when the ANSI encoded files are opened, encoding is shown as UTF-8 itself.

We suggest you to disable this option, verify and let us know if the issue is resolved.



Live Chat Icon For mobile
Up arrow icon