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

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

    This is background information that may explain the answers.

    If with HTML you specify colour #FF9900 you will get what Excel calls Light orange. If you specify colour #003366 you will get what Excel calls Dark teal. But if you want Light orange or Dark teal with vba you must specify &H0099FF and &H663300.

    That is, although the vba function is RGB(&Hrr, &Hgg, &Hbb) the number it generates is &Hbbggrr because that is what the Excel display engine wants.

    I would guess the person who coded the Excel Interop was unaware that Excel uses non standard numbers to specify colours.

提交回复
热议问题