reading color information from multiple xls cells

1 Ansicht (letzte 30 Tage)
Harmen
Harmen am 15 Feb. 2022
Kommentiert: Harmen am 15 Feb. 2022
Hi,
i'm trying to read the Interior.ColorIndex value for multiple cells at once.
it works for 1 cell, but not a range of cells. Any idea how to make this work for more that 1 cell?
handles.ExFileName='r:\Magview\source\data\points.xlsx';
h = actxserver('Excel.Application');
workbook = h.Workbooks.Open(handles.ExFileName);
Sheets = h.ActiveWorkBook.Sheets;
Sheets.Item(1).Activate;
c = h.Range('A1').Interior.ColorIndex % returns 47
c2 = h.Range('A1:A500').Interior.ColorIndex % returns a single NaN
invoke(h, 'Quit');
delete(h)

Antworten (1)

Walter Roberson
Walter Roberson am 15 Feb. 2022
  3 Kommentare
Image Analyst
Image Analyst am 15 Feb. 2022
Since a range of cells could be shaded a range of different colors, what do you expect it to return? I suspect there is not API function to handle that and you'll have to process your cells one cell at a time to get each color in turn.
Harmen
Harmen am 15 Feb. 2022
Hi Image Analyst,
I expect it to return an array of index values.
Just before i try to read the color i read the values in the cells. That works fine with multi cell ranges.
I've been reading cells and colors one at a time but it is really slow. So i thought i would rewrite the code to read multiple cells at once. Been succesfull for the values, but not for colors.
handles.ExFileName='r:\Magview\source\data\points.xlsx';
h = actxserver('Excel.Application');
workbook = h.Workbooks.Open(handles.ExFileName);
Sheets = h.ActiveWorkBook.Sheets;
Sheets.Item(1).Activate;
h.Range('A1:AH500').Select;
DataRange = get(h,'Selection');
m = DataRange.Value; %returns data in 500x34 cell
c = h.Range('A1').Interior.ColorIndex % returns 47
c3 = DataRange.Interior.ColorIndex % returns single NaN
c2 = h.Range('A1:A500').Interior.ColorIndex % returns single NaN
invoke(h, 'Quit');
delete(h)

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by