有人可以帮助我使用 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) })
}};