Hi,
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;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
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;
worksheet.UsedRange.AutofitColumns();
string fileName = "ReportFile.csv");
Stream excelStream = File.Create(fileName);
CultureInfo cultureInfo =CultureInfo.CurrentCulture;
Encoding encoding= Encoding.GetEncoding(cultureInfo.TextInfo.ANSICodePage);
workbook.SaveAs(excelStream, ",", encoding);
excelStream.Dispose();
}
Please help.
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.
Regards,
Keerthi.
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
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.
Regards,
Keerthi.