Changing an Excel cell's backcolor using hex results in Excel displaying completely different color in the spreadsheet

后端 未结 7 1904
灰色年华
灰色年华 2021-02-07 13:27

So I am setting an Excel cell\'s Interior Color to a certain value, like below:

worksheet.Cells[1, 1].Interior.Color = 0xF1DCDB;

However, when

7条回答
  •  渐次进展
    2021-02-07 13:55

    You need to convert the color from hex to Excel's color system as follows:

    ColorConverter cc = new ColorConverter();
    worksheet.Cells[1, 1].Interior.Color = ColorTranslator.ToOle((Color)cc.ConvertFromString("#F1DCDB"));
    

    It's not really a bug, since Excel's color system has always been this way. It's just one more thing that makes C# - Excel interop a pain.

提交回复
热议问题