I am using the 'Export to CSV' feature for several grids in an application and it works for Excel 2007. However, with Excel 2003 there is an issue. Although the column headers appear within individual cells (Columns A, B C etc...), the rows beneath them do not. All rows appear bunched up within Column A. In Excel 2007, the rows appear underneath their individual headers.
Is Excel 2003 supported or can I modify the code, as shown below, so that it is compatible with Excel 2003?
writer.Write(
"Account Id,");
writer.Write(
"Admit Date,");
writer.Write(
"Discharge Date,");
writer.Write(
"Attending,");
writer.Write(
"ClinicCode");
writer.WriteLine();
foreach (GetMPIDataByMRNResult x in mpiData)
{
writer.Write(x.AccountId);
writer.Write(
",");
writer.Write(
"\"");
writer.Write(
String.Format("{0:d}", x.AdmitDate));
writer.Write(
"\"");
writer.Write(
",");
writer.Write(
"\"");
writer.Write(
String.Format("{0:d}", x.DischargeDate));
writer.Write(
"\"");
writer.Write(
",");
writer.Write(
"\"");
writer.Write(x.Attending);
writer.Write(
"\"");
writer.Write(
",");
writer.Write(x.ClinicCode);
writer.WriteLine();
}
writer.Flush();
output.Position = 0;
string fileName = "MPIDataReport_" + MRN + ".csv";
return File(output, "text/comma-separated-values", fileName);
Thanks!
Arnold Smith