setSolidColor throwing unexpected error in Excel J

2019-08-22 01:14发布

The setSolidColor method of the chart series class is throwing an error in Excel 1907 Build 11901.20080 but NOT in Excel 1902 Build 11328.20116.

To demo the error I modified the examples in Script Lab, specifically the section under "charts" called "Create Charts - Create column clustered, line, ...".

The data setup is required, here is the code from Scirptlab. This doesn't demo the error just sets up the data.

async function setup() {
  await Excel.run(async (context) => {
    context.workbook.worksheets.getItemOrNullObject("Sample").delete();
    const sheet = context.workbook.worksheets.add("Sample");

    let expensesTable = sheet.tables.add("A1:E1", true);
    expensesTable.name = "SalesTable";
    expensesTable.getHeaderRowRange().values = [["Product", "Qtr1", "Qtr2", "Qtr3", "Qtr4"]];

    expensesTable.rows.add(null, [
      ["Frames", 5000, 7000, 6544, 4377],
      ["Saddles", 400, 323, 276, 651],
      ["Brake levers", 12000, 8766, 8456, 9812],
      ["Chains", 1550, 1088, 692, 853],
      ["Mirrors", 225, 600, 923, 544],
      ["Spokes", 6005, 7634, 4589, 8765]
    ]);

    sheet.getUsedRange().format.autofitColumns();
    sheet.getUsedRange().format.autofitRows();

    sheet.activate();
    await context.sync();
  });
}

The code that demos the error is below. Note the only addition is the line chart.series.getItemAt(0).format.fill.setSolidColor("CCCCCC");

This throws the error "This operation is not permitted for the current object."

async function createAreaStackedChart() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    const salesTable = sheet.tables.getItem("SalesTable");
    const dataRange = salesTable.getDataBodyRange();

    let chart = sheet.charts.add("AreaStacked", dataRange, "Auto");

    chart.setPosition("H1", "M15");
    chart.title.text = "Quarterly sales chart";
    chart.legend.position = "Bottom";
    chart.legend.format.fill.setSolidColor("white");
    chart.dataLabels.format.font.size = 15;
    chart.dataLabels.format.font.color = "black";
    chart.series.getItemAt(0).name = "Q1";
    chart.series.getItemAt(1).name = "Q2";
    chart.series.getItemAt(2).name = "Q3";
    chart.series.getItemAt(3).name = "Q4";
    chart.series.getItemAt(0).format.fill.setSolidColor("CCCCCC"); //only addition
    await context.sync();
  });
}

I have only seen the error in Excel 1907 Build 11901.20080 but it does not occur in Excel 1902 Build 11328.20116.

0条回答
登录 后发表回答