For some reason, when I open a CSV file, that appears totally fine in Excel and Notepad, in Microsoft Works, there are some strange characters appearing as the first thing in the file. By first thing I mean they appear in cell A1, before the text that appears in that cell.
Here is an example file
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".
I create these files in my application using this method
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");
}
I have a few questions
- Is there a way to change this code to save the files in ANSI format?
- Will I be able to view the files perfectly in Notepad, Works and Excel?
csvfile that shows this behaviour.' – Li-aung Yip May 28 '12 at 15:04