简体   繁体   中英

Why is white reported as black?

Working with openpyxl and coloured cells in Excel, things have been fine - except for blank cells, which I would expect to be:

FFFFFFFF

Only it comes back as

00000000

It's true that filling a cell with RGB 255, 255, 255 does get reported as FFFFFFFF (not that you can visually tell the difference between a white cell and a blank cell)

My question is why is black (RGB 0,0,0) "1" and white (RGB 255, 255, 255) "00000000"?

import openpyxl
import os
myDir = "C:\\Temp\\"
myFile = "colour.xlsx"
fname = os.path.join(myDir, myFile)
from openpyxl import load_workbook
wb = load_workbook(filename = fname)
ws = wb.active

# Selecting the slice of interest
cell_range = ws["A1":"D1"] 

for row in cell_range: # This is iterating through rows 1-7
  for cell in row:
    col = cell.fill.start_color.index
    print col

Pattern fills have foreground and background colours. But they also have a fillType. The values of the colours are irrelevant until there is a fillType. The standard white background for fills should be understood as the absence of a fill.

RGB are an additive color mode (you're adding light to change the color) so no color is black.

In contrast to CMYK which is sustractive color mode. (you adding tints to steal waves of light and refract the one it cannot steal)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM