conditionalFormats property
ConditionalFormats
get
conditionalFormats
Gets the collection of conditional formats in the Range. Read-only.
// Create a new Excel Document.
final Workbook workbook = Workbook();
// Accessing sheet via index.
final Worksheet sheet = workbook.worksheets[0];
//Applying conditional formatting to "A1".
final ConditionalFormats conditions =
sheet.getRangeByName('A1').conditionalFormats;
final ConditionalFormat condition = conditions.addCondition();
//Represents conditional format rule that the value in target range should be between 10 and 20
condition.formatType = ExcelCFType.cellValue;
condition.operator = ExcelComparisonOperator.between;
condition.firstFormula = '10';
condition.secondFormula = '20';
sheet.getRangeByIndex(1, 1).setText('Enter a number between 10 and 20');
//Setting format properties to be applied when the above condition is met.
condition.backColor = '#66FF99';
condition.isBold = true;
condition.isItalic = true;
//save and dispose.
final List<int> bytes = workbook.saveAsStream();
File('ConditionalFormatting.xlsx').writeAsBytes(bytes);
workbook.dispose();
Implementation
ConditionalFormats get conditionalFormats {
if (isSingleRange) {
cfValue = getColumnName(column) + row.toString();
} else {
cfValue =
'${getColumnName(column)}$row:${getColumnName(lastColumn)}$lastRow';
}
return _worksheet.createCondFormatCollectionWrapper(this, cfValue);
}