フィルターのクリア

Get information from Excel file based on cell color

24 ビュー (過去 30 日間)
Ghenji
Ghenji 2018 年 1 月 29 日
編集済み: Ghenji 2018 年 3 月 2 日
How can i get information of the cell fill in an excel file. Like there could be more than one cell coloured.

採用された回答

Guillaume
Guillaume 2018 年 1 月 29 日
編集済み: Guillaume 2018 年 1 月 29 日
It is certainly possible to query the cell colour in an excel spreadsheet from matlab (only on Windows, with Excel installed) however you will need to be familiar with Excel object Model. In addition, there is no function in Excel to find all the cells of a specific colour, so you'll have to loop over the cells and query their colour one by one.
If either of these is an obstacle, I would suggest that you find a different way of defining your cell range.
Here is an example of how to query the colour of a cell:
filename = 'C:\somewhere\someexcelfile.xlsx';
sheetname = 'SomeSheetName';
cell = 'A1';
excel = actxserver('Excel.Application'); %start excel
excel.Visible = true; %optional, make excel visible
workbook = excel.Workbooks.Open(filename); %open excel file
worksheet = workbook.Worksheets.Item(sheetname); %get worksheet reference
rgb = worksheet.Range(cell).Interior.Color;
red = mod(rgb, 256);
green = floor(mod(rgb / 256, 256));
blue = floor(rgb / 65536);
workbook.Close;
excel.Quit;
  2 件のコメント
Ghenji
Ghenji 2018 年 1 月 29 日
Thank you for your answer. But I don't have fixed range for cells that's why I would like the code to skim through complete sheet, detect the color and give me information.
Guillaume
Guillaume 2018 年 1 月 29 日
As I said you'll have to loop over the cells of interest. Something like:
%worksheet = ...
interiorcolor = zeros(31, 6);
for row = 1:31
for column = 1:6
interiorcolor(row, column) = worksheet.Cells.Item(column, row).Interior.Color;
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by