From 7e061d0b0a00ef2f46465a6da29d37cb8aebe618 Mon Sep 17 00:00:00 2001 From: Alex Jerabek <38896772+AlexJerabek@users.noreply.github.com> Date: Mon, 21 Jul 2025 15:12:56 -0700 Subject: [PATCH] Add data bar conditional formatting samples --- docs/sample-scripts/samples.yaml | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/sample-scripts/samples.yaml b/docs/sample-scripts/samples.yaml index a6179d8d..2c875943 100644 --- a/docs/sample-scripts/samples.yaml +++ b/docs/sample-scripts/samples.yaml @@ -934,6 +934,48 @@ format.getFill().setColor("yellow"); format.getFont().setItalic(true); } +'ExcelScript.ConditionalDataBarNegativeFormat:interface': + - |- + /** + * This script applies data bar conditional formatting to a range. + * It sets the data bar colors to be green when positive and red when negative. + */ + function main(workbook: ExcelScript.Workbook) { + // Get the "Sales" data column range in a table named "SalesTable". + const table = workbook.getTable("SalesTable"); + const salesRange = table.getColumnByName("Sales").getRangeBetweenHeaderAndTotal(); + + // Add data bar conditional formatting to the range. + const cf = salesRange.addConditionalFormat(ExcelScript.ConditionalFormatType.dataBar); + + // Have the bar show green when positive and red when negative. + const dataBarConditionalFormat = cf.getDataBar(); + const positiveFormat: ExcelScript.ConditionalDataBarPositiveFormat = dataBarConditionalFormat.getPositiveFormat(); + positiveFormat .setFillColor("green"); + const negativeFormat: ExcelScript.ConditionalDataBarNegativeFormat = dataBarConditionalFormat.getNegativeFormat(); + negativeFormat.setFillColor("red"); + } +'ExcelScript.ConditionalDataBarPositiveFormat:interface': + - |- + /** + * This script applies data bar conditional formatting to a range. + * It sets the data bar colors to be green when positive and red when negative. + */ + function main(workbook: ExcelScript.Workbook) { + // Get the "Sales" data column range in a table named "SalesTable". + const table = workbook.getTable("SalesTable"); + const salesRange = table.getColumnByName("Sales").getRangeBetweenHeaderAndTotal(); + + // Add data bar conditional formatting to the range. + const cf = salesRange.addConditionalFormat(ExcelScript.ConditionalFormatType.dataBar); + + // Have the bar show green when positive and red when negative. + const dataBarConditionalFormat = cf.getDataBar(); + const positiveFormat: ExcelScript.ConditionalDataBarPositiveFormat = dataBarConditionalFormat.getPositiveFormat(); + positiveFormat .setFillColor("green"); + const negativeFormat: ExcelScript.ConditionalDataBarNegativeFormat = dataBarConditionalFormat.getNegativeFormat(); + negativeFormat.setFillColor("red"); + } 'ExcelScript.ConditionalDataBarRule:interface': - |- /**