I am trying to format a excel spreadsheet on the fly. The data is written to it using a streamwriter. I tried formatting the streamwriter but i can't do much with it. I need to add the header bold, with background color and grid lines to the cells.
Can anyone please help me with it?
#region "Excel Methods"
private void ExportGridViewToCSV(DataTable dt, string fileName)
string path = HttpContext.Current.Server.MapPath(fileName);
StreamWriter sw = new StreamWriter(path, false);
// Write the headers.
for (int i = 0; i < dt.Columns.Count; i++)
sw.Write("\"" + dt.Columns[i] + "\"");
if (i < dt.Columns.Count - 1)
// Write the content.
foreach (DataRow row in dt.Rows)
for (int j = 0; j < dt.Columns.Count; j++)
if (row[j].ToString().Trim() == " ")
sw.Write("\"" + "" + "\"");
View Complete Post