2

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());
Mohan Kurali
  • 362
  • 1
  • 4
  • 15
  • 1
    It seems that encoding isn't problem in your case. Without more code it's hard to tell, but it looks like your file content is not csv but something else and you still save it as csv - that's why warning shows. – Piotr Wojsa Jan 30 '19 at 14:40
  • content is in the string format @PiotrWojsa – Mohan Kurali Jan 31 '19 at 13:17
  • Without a [MCVE](https://stackoverflow.com/help/mcve) is hard to help you. Please, post a code we can test ourselves and the provided input. – Magnetron Feb 01 '19 at 10:21

0 Answers0