How to open an Excel file with encoding in .NET Core?

8 Dec 20231 minute to read

XlsIO do not have direct support to open an Excel file with encoding in .NET Core. But this can be acheived through below workaround.

using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;

  FileStream stream = new FileStream("Sample.csv", FileMode.Open, FileAccess.Read);
  System.Text.UnicodeEncoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
  IWorkbook workbook = application.Workbooks.Open(stream, System.Text.UnicodeEncoding.GetEncoding("big5"));

  FileStream outputStream = new FileStream("Output.csv", FileMode.Create, FileAccess.Write);
  workbook.SaveAs(outputStream, ",");
}