0

有人可以帮助我使用 Office JS API 仅更新 Excel 表中的特定列。我只想更新列PSID名称,如下图所示。我正在使用带有 React 和 TypeScript 的yo Office模板的项目脚手架的 Node JS。

在此处输入图像描述

我正在尝试的代码:

handleSubmit = async () => {
try {
  await Excel.run(async context => {
    var sheet = context.workbook.worksheets.getItem("Tech-Panel");
    var expensesTable = sheet.tables.add("A1:B1", true);//.getItem("TechPannelTable");

    const { PSID, Name, itcEmailIds, clientEmailIds, contactNo, skills, panelStatus,
      client, itcManager, availability, preferredTime, remarks } = this.state.techPanelEntry;

      expensesTable.getHeaderRowRange().values = [["PSID", "Name"]]
      /*expensesTable.rows.add(null, [
        [PSID, Name, itcEmailIds, clientEmailIds, contactNo, skills,
          panelStatus, (dateOfInactive != null ? dateOfInactive.toLocaleDateString("en-US") : null), client, itcManager, availability, preferredTime, remarks]
      ]);*/
      expensesTable.rows.add(null, [
        [PSID, Name]
      ]);

    
    if (Office.context.requirements.isSetSupported("ExcelApi", "1.2")) {
      sheet.getUsedRange().format.autofitColumns();
      sheet.getUsedRange().format.autofitRows();
    }
    await context.sync();
    this.setState({
      ...this.state,
      techPanelEntry: defaultTechPanel()
    })
  });
} catch (error) {
  this.setState({ error: JSON.stringify(error) })
}};
4

1 回答 1

0

你可以参考这个来更新你需要的任何列:table.columns.items[1].getDataBodyRange().values = [["aa"], ["bb"], ["cc"], ["dd" ], ["dee"], ["gg"], ["uu"]];

于 2021-04-12T01:41:16.577 回答