问题与csv导出没有关系,如果你用记事本打开csv文件就很好了. Excel将自动检测单元格类型作为日期并将其显示为日期.
要避免此行为,请在引号之间包装文本并在其前面加上a =,如下所示:
= "DEC20"
该文件应该成为
= "field1", = "field2", = "field...", = "DEC20", ...
你的方法应该成为:
for (int i = 0; i < myData.Count(); i++)
{
sb.AppendLine(string.Join(delimiter,
" = \"",
Common.FormatExportString(myData[i].Code),
Common.FormatExportString(myData[i].Name),
Common.FormatExportString(myData[i].Description)
"\""));
}
//returns the file after writing the stream to the csv file.
return File(new System.Text.UTF8Encoding().GetBytes(sb.ToString()), "text/csv", fileName);