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.