Newbie: Reading color information

  • Thread starter Thread starter pinkfloydhomer
  • Start date Start date
P

pinkfloydhomer

Word of caution: I have _never_ done any excel programming before (lots
of C++, C, Python, Java etc. though).

I have an excel file that contains 25 worksheets.

Each sheet contains (apart from som text here and there) a 12x12 grid
of cells containing mainly just color information. That is, a cell is
white, green, red, blue etc. In some of these colored cells, there is
also text.

Now, I need to extract data from these sheets into some simple format
that is easy to parse. I have tried using a Python excel reading
module, but it disregards color information.

Is there some tools that can extract data (also color information) from
excel into some simpler format (CSV is without color information too)?

Or can I make a simple excel program that puts a certain string into a
cell depending on each color? Then I can read this content with the
python module etc.

/David
 
If you select some cells and run this macro:

Sub colorcode()
Dim r As Range
For Each r In Selection
r.Value = r.Interior.ColorIndex
Next
End Sub


The contents of the cells will be set to the background color index.
 
If you select some cells and run this macro:

Sub colorcode()
Dim r As Range
For Each r In Selection
r.Value = r.Interior.ColorIndex
Next
End Sub

The contents of the cells will be set to the background color index.

If you want RGB values, the Interior.Color property (I'm not sure which
XL version this appeared in, but probably 2000) returns a Long, which
can be transformed into RGB values using something like this:

Dim R As Long
Dim G As Long
Dim B As Long

R = colorValue Mod 256
G = (colorValue - R) / 256 Mod 256
B = (colorValue - R - G * 256) / 256 / 256 Mod 256

Mike
 
Back
Top