0

我正在尝试为 Excel 创建一个“Office 插件”,但遇到以下问题。这发生在更新服务器后。

设置:

  • Excel API 1.1
  • Windows Server 2019 标准版 (17763.2565)
  • 办公室 2016 (16.0.52)

代码:

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);
  }
}

结果是:

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"}

在此处输入图像描述

4

0 回答 0