//create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); // Prepare data worksheet.getRange("A1:C3").setValue("Text"); IRange b2 = worksheet.getRange("B2"); b2.getInterior().setColor(Color.GetRed()); b2.getFont().setColor(Color.GetWhite()); b2.setValue("B2"); IRange a2 = worksheet.getRange("A2"); a2.getInterior().setColor(Color.GetOrange()); a2.getFont().setColor(Color.GetWhite()); a2.setValue("A2"); // Find cells with red background and white foreground, // and highlight them with bold and bigger text // Create a temporary sheet to build a IDisplayFormat IWorksheet displayFormatFactoryWorksheet = workbook.getWorksheets().add(); IRange displayFormatFactoryRange = displayFormatFactoryWorksheet.getRange("A1"); displayFormatFactoryRange.getInterior().setColor(Color.GetRed()); displayFormatFactoryRange.getFont().setColor(Color.GetWhite()); IDisplayFormat searchFormat = displayFormatFactoryRange.getDisplayFormat(); // Find the first occurrence IRange searchRange = worksheet.getUsedRange(); FindOptions options = new FindOptions(); options.setSearchFormat(searchFormat); IRange foundCell = searchRange.find("*", null, options); // Highlight the found range foundCell.getFont().setBold(true); foundCell.getFont().setSize(foundCell.getFont().getSize() + 8); // Dispose the temporary sheet displayFormatFactoryWorksheet.delete(); //save to an excel file workbook.save("FindDisplayFormat.xlsx");
//create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) // Prepare data worksheet.getRange("A1:C3").value = "Text" val b2 = worksheet.getRange("B2") b2.interior.color = Color.GetRed() b2.font.color = Color.GetWhite() b2.value = "B2" val a2 = worksheet.getRange("A2") a2.interior.color = Color.GetOrange() a2.font.color = Color.GetWhite() a2.value = "A2" // Find cells with red background and white foreground, // and highlight them with bold and bigger text // Create a temporary sheet to build a IDisplayFormat val displayFormatFactoryWorksheet = workbook.worksheets.add() val displayFormatFactoryRange = displayFormatFactoryWorksheet.getRange("A1") displayFormatFactoryRange.interior.color = Color.GetRed() displayFormatFactoryRange.font.color = Color.GetWhite() val searchFormat = displayFormatFactoryRange.displayFormat // Find the first occurrence val searchRange = worksheet.usedRange val options = FindOptions() options.searchFormat = searchFormat val foundCell = searchRange.find("*", null, options) // Highlight the found range foundCell.font.bold = true foundCell.font.size = foundCell.font.size + 8 // Dispose the temporary sheet displayFormatFactoryWorksheet.delete() //save to an excel file workbook.save("FindDisplayFormat.xlsx")