Excel.ConditionalFormatType enum
Hinweise
Beispiele
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/14-conditional-formatting/conditional-formatting-advanced.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
queueCommandsToClearAllConditionalFormats(sheet);
const temperatureDataRange = sheet.tables.getItem("TemperatureTable").getDataBodyRange();
/* When the priority property of ConditionalFormat objects
is not explicitly set, they are prioritized in the order
that they are added, with zero-based numbering: 0, 1, ...
Contradictions are resolved in favor of the format with
the lower priority number. In the example below, negative
numbers will get a green background, but NOT a blue font,
because priority goes to the format that gives them a red font.
*/
// Set low numbers to bold, dark red font. This format will
// get priority 0.
const presetFormat = temperatureDataRange.conditionalFormats
.add(Excel.ConditionalFormatType.presetCriteria);
presetFormat.preset.format.font.color = "red";
presetFormat.preset.format.font.bold = true;
presetFormat.preset.rule = { criterion: Excel.ConditionalFormatPresetCriterion.oneStdDevBelowAverage };
// Set negative numbers to blue font with green background.
// This format will get priority 1.
const cellValueFormat = temperatureDataRange.conditionalFormats
.add(Excel.ConditionalFormatType.cellValue);
cellValueFormat.cellValue.format.font.color = "blue";
cellValueFormat.cellValue.format.fill.color = "lightgreen";
cellValueFormat.cellValue.rule = { formula1: "=0", operator: "LessThan" };
await context.sync();
});
Felder
cellValue = "CellValue" | |
colorScale = "ColorScale" | |
containsText = "ContainsText" | |
custom = "Custom" | |
dataBar = "DataBar" | |
iconSet = "IconSet" | |
presetCriteria = "PresetCriteria" | |
topBottom = "TopBottom" |
Zusammenarbeit auf GitHub
Die Quelle für diesen Inhalt finden Sie auf GitHub, wo Sie auch Issues und Pull Requests erstellen und überprüfen können. Weitere Informationen finden Sie in unserem Leitfaden für Mitwirkende.
Office Add-ins