Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getCellColor()
- clear all;
- clc;
- % Excel
- filename = 'colorTest.xlsx';
- % Start Excel as ActiveX server process on local host
- Excel = actxserver('Excel.Application');
- % Handle requested Excel workbook filename
- path = validpath(filename);
- % Cleanup tasks upon function completion
- cleanUp = onCleanup(@()xlsCleanup(Excel, path));
- % Open Excel workbook.
- readOnly = true;
- [~, workbookHandle] = openExcelWorkbook (Excel, path, readOnly);
- % Initialise worksheets object
- workSheets = workbookHandle.Worksheets;
- % Get the sheet object (sheet #1)
- sheet = get(workSheets,'item',1);
- % Print table headers
- fprintf('Color t Int t R G Bn');
- fprintf('--------t --------t -----n');
- % Create figure
- figure;
- hold on;
- % Loop through every color on the Excel file
- for row = 1:8
- % Get the cell object with name of color
- cell = get(sheet, 'Cells', row, 1);
- cName = cell.value;
- % Get the cell object with colored background
- cell = get(sheet, 'Cells', row, 2);
- % Get the interior object
- interior = cell.Interior;
- % Get the color integer property
- cInt = get(interior, 'Color');
- % Get the RGB triplet from its integer value
- cRGB = int2rgb(cInt);
- % Plot the color
- patch([0 0 1 1], [8-row 9-row 9-row 8-row], cRGB);
- % Print row with color data
- fprintf('%-8st %8dt %d %d %dn', cName, cInt, cRGB);
- end
- % Turn off axes
- set(findobj(gcf, 'type','axes'), 'Visible','off')
- end
- function[RGB] = int2rgb(colorInt)
- % Returns RGB triplet of an RGB integer.
- if colorInt > 16777215 || colorInt < 0
- error ('Invalid int value. Valid range: 0 <= value <= 16777215')
- end
- R = floor(colorInt / (256*256));
- G = floor((colorInt - R*256*256)/256);
- B = colorInt - R*256*256 - G*256;
- RGB = [R, G, B]/255;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement