Search code examples
exceloffice-jsoffice-addinsexcel-addinsexcel-web-addins

Excel API 1.1 - error while adding content to table


I'm trying to create an ```Office add-in`` for Excel but encounter the following problem. This occurred after updating de server.

Setup:

  • Excel API 1.1
  • Windows Server 2019 Standard (17763.2565)
  • Office 2016 (16.0.52)

Code:

export async function run() {
  try {
    Excel.run(function (context) {
      //var sheet = context.workbook.worksheets.getItem("Sample");
      var sheet = context.workbook.worksheets.getActiveWorksheet();
      var expensesTable = sheet.tables.add("A1:D1", true /*hasHeaders*/);
      expensesTable.name = "ExpensesTable";
  
      expensesTable.getHeaderRowRange().values = [["Date", "Merchant", "Category", "Amount"]];
  
      expensesTable.rows.add(null /*add rows to the end of the table*/, [
        ["1/1/2017", "The Phone Company", "Communications", "$120"],
        ["1/2/2017", "Northwind Electric Cars", "Transportation", "$142"],
        ["1/5/2017", "Best For You Organics Company", "Groceries", "$27"],
        ["1/10/2017", "Coho Vineyard", "Restaurant", "$33"],
        ["1/11/2017", "Bellows College", "Education", "$350"],
        ["1/15/2017", "Trey Research", "Other", "$135"],
        ["1/15/2017", "Best For You Organics Company", "Groceries", "$97"]
      ]);
  
      sheet.activate();
  
      return context.sync();
    })
    .catch(function (error) {
      console.log("Error: " + error);
      if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
      }
    });
  } catch (error) {
    console.error(error);
  }
}

results in:

Error: InvalidArgument: The argument is invalid or missing or has an incorrect format.
Debug info: {"code":"InvalidArgument","message":"The argument is invalid or missing or has an incorrect format.","errorLocation":"TableRowCollection.add"}

enter image description here


Solution

  • Adding an extra argument as first parameter worked for me

    expensesTable.rows.add(null,null, [["1/1/2017", "The Phone Company", "Communications", "$120"]])