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;
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);
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.
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
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.