I am writing csv file from Datatable. Check my code below
public static void SaveDataTableToCsvFile(string AbsolutePathAndFileName, DataTable TheDataTa
CSV is a pure data format without any formatting. It's a plain text file after all. So no, there is no way of adding colour.
Joey is absolutely right.
But if your situation allows you to output an XLSX instead of a CSV, then EPPlus might be the solution for you.
e.g.
using (ExcelPackage ep = new ExcelPackage(AbsolutePathAndFileName))
{
ExcelWorksheet worksheet = ep.Workbook.Worksheets.Add("Worksheet1");
worksheet.Cells["A1"].LoadFromDataTable(TheDataTable, true);
worksheet.Cells["F4"].BackgroundColor.SetColor(Color.Red);
ep.Save();
}
A CSV (comma-separated values) file is a text file. There is no way to add color too the file without changing it to another file format (such as RTF).
You might want to output an .xls (or equivalent) instead of a .csv using some external utility Or convert the csv to .xls in order to have color coding even possible