Office365 无法在excel web加载项中创建表

Office365 无法在excel web加载项中创建表,office365,office-js,office-addins,excel-addins,Office365,Office Js,Office Addins,Excel Addins,我已经编写了一个函数来创建表 经调查后:- 问题是代码在一张工作表上添加名为“tableName”的表时效果很好,但是如果我在另一张工作表上插入另一个名为“tableName”的表,它会抛出一个错误,并且不会插入没有内容的表。 我需要将名称应用到表中,因为我想根据需要检索表,并且我正在借助其名称进行操作。阅读一篇文章,但如果我重命名工作表名称,然后如何访问它呢 错误: 出了点问题!!!RichApi.Error:参数无效或丢失,或格式不正确。 在新的c() 在b.f.processReques

我已经编写了一个函数来创建表

经调查后:- 问题是代码在一张工作表上添加名为“tableName”的表时效果很好,但是如果我在另一张工作表上插入另一个名为“tableName”的表,它会抛出一个错误,并且不会插入没有内容的表。 我需要将名称应用到表中,因为我想根据需要检索表,并且我正在借助其名称进行操作。阅读一篇文章,但如果我重命名工作表名称,然后如何访问它呢


错误: 出了点问题!!!RichApi.Error:参数无效或丢失,或格式不正确。 在新的c() 在b.f.processRequestExecutorResponseMessage()处 在 在ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke() 在Object.onInvoke()处 在ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke() 在Zone.push../node_modules/Zone.js/dist/Zone.js.Zone.run()处 在 在ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask()处 在Object.onInvokeTask()处


代码

createTable(tableName, startColumn, endColumn, headerData, bodyData, onTableChangedCallback, onSelectionChangedCallback){
Excel.run((context)=> {
  var sheet = context.workbook.worksheets.getActiveWorksheet();
  let colRange = startColumn+":"+endColumn;//like B2:D2
  var sfTable = sheet.tables.add(colRange, true /*hasHeaders*/);
  sfTable.name = "tableName";
  let headerRow = [];
  headerRow.push(headerData);//Below code is hardcoded for 4 column for now


  var tableHeaderRange = sfTable.getHeaderRowRange();
  tableHeaderRange.values = 
  [["Date", "Merchant", "Category", "Amount"]];

  sfTable.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"]
  ]);



  if (Office.context.requirements.isSetSupported("ExcelApi", "1.2")) {
      sheet.getUsedRange().format.autofitColumns();
      //sheet.getUsedRange().format.autofitRows();
      sheet.getUsedRange().format.rowHeight = 15;
  }
  sfTable.onChanged.add(onTableChangedCallback);
  sfTable.onSelectionChanged.add(onSelectionChangedCallback)
  sheet.activate();

  return context.sync(); 
})
.catch((err)=>{
  this.errorHandlerFunction(err,"create table")
});

}

错误的原因非常不寻常。但问题在于同名的表。当我以不同的名称命名时,错误被删除。

错误的原因非常不寻常。但问题在于同名的表。当我以不同的名称命名时,错误被删除。

我无法重新处理此问题,我已经尝试在我的代码中使用您的函数,如果需要重新编写此问题,请检查并更新?谢谢,这是我的要点:你能在每张excel网页上创建表格吗?是的,我能用我的要点成功地创建表格,你能试试这个要点吗:gist.github.com/lumin2008/b3d9261f0c6dc9f6a31078fa1b72a8dc@RaymondLu请阅读问题我已更改了几点..感谢您的努力。是否要创建两个同名表?我无法重新编写此问题,我已尝试在代码中使用您的函数,如有必要,请您审查并更新此问题,好吗?谢谢,这是我的要点:你能在每张excel网页上创建表格吗?是的,我能用我的要点成功地创建表格,你能试试这个要点吗:gist.github.com/lumin2008/b3d9261f0c6dc9f6a31078fa1b72a8dc@RaymondLu请阅读问题我已经改变了几点。谢谢你们的努力。你们想创建两个同名的表吗?