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

后端 未结 7 1890
灰色年华
灰色年华 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:49

    The RGB colour alone can be parsed from an HTML hex string:

    Color colour = ColorTranslator.FromHtml("#E7EFF2");
    

    If you have a separate alpha value you can then apply this (docs):

    Color colour = ColorTranslator.FromHtml("#E7EFF2");
    Color transparent = Color.FromArgb(128, colour);
    

提交回复
热议问题