Write csv file with color code

前端 未结 4 1719
鱼传尺愫
鱼传尺愫 2020-12-19 23:49

I am writing csv file from Datatable. Check my code below

      public static void SaveDataTableToCsvFile(string AbsolutePathAndFileName, DataTable TheDataTa         


        
相关标签:
4条回答
  • 2020-12-19 23:54

    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.

    0 讨论(0)
  • 2020-12-20 00:04

    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();
    }
    
    0 讨论(0)
  • 2020-12-20 00:15

    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).

    0 讨论(0)
  • 2020-12-20 00:18

    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

    0 讨论(0)
提交回复
热议问题