仅更新 Office 加载项中的特定列 (Javascript Excel JS API)
Update only specific columns in Office AddIn (Javascript Excel JS API)
谁能帮助我使用 Office JS API 仅更新 Excel Table 中的特定列。我只想更新 PSID 和 Name 列,如下图所示。我将 Node JS 与 yo Office 模板与 React 和 TypeScript 搭建的项目一起使用。
我尝试的代码:
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) })
}};
您可以参考这个来更新您需要的任何栏目:
table.columns.items[1].getDataBodyRange().values = [["aa"], ["bb"], ["cc"], ["dd"], ["dee"], ["gg" ], ["uu"]];
谁能帮助我使用 Office JS API 仅更新 Excel Table 中的特定列。我只想更新 PSID 和 Name 列,如下图所示。我将 Node JS 与 yo Office 模板与 React 和 TypeScript 搭建的项目一起使用。
我尝试的代码:
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) })
}};
您可以参考这个来更新您需要的任何栏目: table.columns.items[1].getDataBodyRange().values = [["aa"], ["bb"], ["cc"], ["dd"], ["dee"], ["gg" ], ["uu"]];