I can't change the chart column color in Excel Office scripts

31 views Asked by At

I tried to use office scripts in Excel and I made a simple chart and tried to change its color but I noticed that it didn't change after I ran the script also I had this message: This action cannot be recorded

I first made the chart and then saved the script but it gave me the original chart before I made any change on the chart like color...in the same time I see videos it show its normal to save any changes in the charts.

this is that changes that I made:

1

this is the first chart before I made any change:

2

1

There are 1 answers

0
taller On
  • Assuming you are looking for changing the color of existing chart
function main(workbook: ExcelScript.Workbook) {
    let selectedSheet = workbook.getActiveWorksheet();
    let chartObject = selectedSheet.getCharts()[0];
    if(chartObject){
        chartObject.getSeries()[0].getFormat().getFill().setSolidColor("#00FF00");
    }

  • If you try to create a chart with OfficeScript and change its color
function main(workbook: ExcelScript.Workbook) {
    let selectedSheet = workbook.getActiveWorksheet();
    // // Insert chart on sheet selectedSheet
    let chartObject = selectedSheet.addChart(ExcelScript.ChartType.columnClustered, selectedSheet.getRange("A1:B5"));
    // Set fill color on series for a chart
    chartObject.getSeries()[0].getFormat().getFill().setSolidColor("#00FF00");
}