how to change the encoding of ExcelPackage() in epplus

2.7k Views Asked by At

Is there any way to encode the ExcelPackage() to UTF-8 format. I have already tried ExcelTextFormat() but does not resolve my issue. The issue is that when I export a CSV file it displays a warning "file format and extension of fileName.csv does not match".

if (documentType.ToLower() == "csv")   
{
  contentType = OptixAuditConstants.CsvMimeType;
  fileName = fileName + OptixAuditConstants.CsvExtension;
  var data = ConvertToCsv(worksheet);
  var filtersum = ConvertToCsv(worksheet1);
  var format = new ExcelTextFormat();
  format.Delimiter = ';';
  format.Encoding = Encoding.UTF8;
  worksheet.Cells.LoadFromText(data, format);
  worksheet1.Cells.LoadFromText(filtersum, format);
}
AuditLogger.Current.Info(string.Concat(OptixAuditConstants.DownloadWidgetData, CommonConstants.ExitingMethod));

return File(package.GetAsByteArray(), contentType, fileName.Trim());
0

There are 0 best solutions below