|
934 | 934 | format.getFill().setColor("yellow");
|
935 | 935 | format.getFont().setItalic(true);
|
936 | 936 | }
|
| 937 | +'ExcelScript.ConditionalDataBarNegativeFormat:interface': |
| 938 | + - |- |
| 939 | + /** |
| 940 | + * This script applies data bar conditional formatting to a range. |
| 941 | + * It sets the data bar colors to be green when positive and red when negative. |
| 942 | + */ |
| 943 | + function main(workbook: ExcelScript.Workbook) { |
| 944 | + // Get the "Sales" data column range in a table named "SalesTable". |
| 945 | + const table = workbook.getTable("SalesTable"); |
| 946 | + const salesRange = table.getColumnByName("Sales").getRangeBetweenHeaderAndTotal(); |
| 947 | +
|
| 948 | + // Add data bar conditional formatting to the range. |
| 949 | + const cf = salesRange.addConditionalFormat(ExcelScript.ConditionalFormatType.dataBar); |
| 950 | +
|
| 951 | + // Have the bar show green when positive and red when negative. |
| 952 | + const dataBarConditionalFormat = cf.getDataBar(); |
| 953 | + const positiveFormat: ExcelScript.ConditionalDataBarPositiveFormat = dataBarConditionalFormat.getPositiveFormat(); |
| 954 | + positiveFormat .setFillColor("green"); |
| 955 | + const negativeFormat: ExcelScript.ConditionalDataBarNegativeFormat = dataBarConditionalFormat.getNegativeFormat(); |
| 956 | + negativeFormat.setFillColor("red"); |
| 957 | + } |
| 958 | +'ExcelScript.ConditionalDataBarPositiveFormat:interface': |
| 959 | + - |- |
| 960 | + /** |
| 961 | + * This script applies data bar conditional formatting to a range. |
| 962 | + * It sets the data bar colors to be green when positive and red when negative. |
| 963 | + */ |
| 964 | + function main(workbook: ExcelScript.Workbook) { |
| 965 | + // Get the "Sales" data column range in a table named "SalesTable". |
| 966 | + const table = workbook.getTable("SalesTable"); |
| 967 | + const salesRange = table.getColumnByName("Sales").getRangeBetweenHeaderAndTotal(); |
| 968 | +
|
| 969 | + // Add data bar conditional formatting to the range. |
| 970 | + const cf = salesRange.addConditionalFormat(ExcelScript.ConditionalFormatType.dataBar); |
| 971 | +
|
| 972 | + // Have the bar show green when positive and red when negative. |
| 973 | + const dataBarConditionalFormat = cf.getDataBar(); |
| 974 | + const positiveFormat: ExcelScript.ConditionalDataBarPositiveFormat = dataBarConditionalFormat.getPositiveFormat(); |
| 975 | + positiveFormat .setFillColor("green"); |
| 976 | + const negativeFormat: ExcelScript.ConditionalDataBarNegativeFormat = dataBarConditionalFormat.getNegativeFormat(); |
| 977 | + negativeFormat.setFillColor("red"); |
| 978 | + } |
937 | 979 | 'ExcelScript.ConditionalDataBarRule:interface':
|
938 | 980 | - |-
|
939 | 981 | /**
|
|
0 commit comments