出于某种原因,当我打开一个在 Excel 和记事本中看起来完全正常的 CSV 文件时,在 Microsoft Works 中,文件中首先出现了一些奇怪的字符。首先,我的意思是它们出现在单元格 A1 中,在该单元格中出现的文本之前。
这是一个示例文件
Illustration carrier,Net death benefit,Issue date,Issue state,Policy type,Member lives,Policy date,Termination of coverage,Termination of coverage action required,Accumulated value,AV,SV,Illustrated Annual Level Premiums,LP to NDB ratio,Premium financed,Name of program,Primary insured age,Primary insured gender,Secondary insured age,Secondary insured gender,Current bid,Time left,Bid1,Bid2,Bid3,Bid4,Bid5,Bid6,Bid7,Bid8,Bid9,Bid10,Bid11,Bid12,Bid13,Bid14,Bid15,Bid16,Bid17,Bid18,Bid19,Bid20
srwer,$0.00,14/05/2012,us state 2,policy Type 1,member life 4,16/05/2012,-,,$0.00,-,-,,Not yet implemented,no,,0y 0m,Demale,,Female,$0.00,"2 days, 7 hours, 51 minutes, 36 seconds".
我使用这种方法在我的应用程序中创建这些文件
protected ActionResult ExportToCSV(string csvExport)
{
var output = new MemoryStream();
var writer = new StreamWriter(output, Encoding.UTF8);
writer.Write(csvExport);
writer.Flush();
output.Position = 0;
return File(output, "text/comma-seperated-values", "export.csv");
}
我有几个问题
- 有没有办法更改此代码以将文件保存为 ANSI 格式?
- 我能否在记事本、Works 和 Excel 中完美查看文件?