Skip to content

[excel] (Conditional Formatting) Add data bar conditional formatting samples #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/sample-scripts/samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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':
- |-
/**
Expand Down