有没有办法将 ExcelPackage() 编码为 UTF-8 格式。我已经尝试过 ExcelTextFormat() 但没有解决我的问题。问题是,当我导出 CSV 文件时,它会显示警告“fileName.csv 的文件格式和扩展名不匹配”。
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());