Capture cell range for specific color and bold font

Hi Support,

We have two requirements as below:

  1. Can we capture the cell range where it contains some specific color like I have excel file and B3-E3 and A8- D8 cell contains yellow color then is there any support available where we provide the color code and it will display the cell range that B3-E3 and A8-D8 contains yellow color code. If available lease provide me the code snippet.

  2. Can I capture the cell range where it contains bold font. If available lease provide me the code snippet.

Please update.

Hi,

Thanks for your posting and using Aspose.Cells.

Please use FindOptions.Style for your needs. It will enable you to search cells with specific style or formatting. Please see the following sample code, its sample excel file and the console output. I have also attached the screenshot for your reference.

The code searches all the cells which has same style (formatting) as cell A1. So all the cells with black circles as shown inside the screenshot will be found because their formatting matches with cell A1’s formatting.

Java

//Load sample excel file
Workbook wb = new Workbook(dirPath + “sampleFindCellByCellFormat.xlsx”);

//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);

//Get the format of cell
Cell a1 = ws.getCells().get(0);
Style st = a1.getStyle();

//Find all the cell that have same format and print their cell names
Cell cell = null;

//Create find options, we want to search by cell format
FindOptions opts = new FindOptions();
opts.setStyle(st);

//Find the first cell
cell = ws.getCells().find(null, cell, opts);

while(cell!=null)
{
//Print the cell information
System.out.println(cell);

//Find the next cell
cell = ws.getCells().find(null, cell, opts);
}

C#

//Load sample excel file
Workbook wb = new Workbook(“sampleFindCellByCellFormat.xlsx”);

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Get the format of cell
Cell a1 = ws.Cells[0];
Style st = a1.GetStyle();

//Find all the cell that have same format and print their cell names
Cell cell = null;

//Create find options, we want to search by cell format
FindOptions opts = new FindOptions();
opts.Style = st;

//Find the first cell
cell = ws.Cells.Find(null, cell, opts);

while(cell!=null)
{
//Print the cell information
Debug.WriteLine(cell);
Console.WriteLine(cell);

//Find the next cell
cell = ws.Cells.Find(null, cell, opts);
}

Console Output
Aspose.Cells.Cell [ A1; ValueType : IsString; Value : Test ]
Aspose.Cells.Cell [ J4; ValueType : IsString; Value : Abc ]
Aspose.Cells.Cell [ G10; ValueType : IsString; Value : Def ]
Aspose.Cells.Cell [ E12; ValueType : IsString; Value : Ghi ]
Aspose.Cells.Cell [ B18; ValueType : IsString; Value : Jkl ]