Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kreja/a7c2b0fd648c7613e2aa47e7e5b05d75 to your computer and use it in GitHub Desktop.
Save kreja/a7c2b0fd648c7613e2aa47e7e5b05d75 to your computer and use it in GitHub Desktop.
delete table rows doesn’t trigger onChanged - 与Script Lab共享
name: delete table rows doesn’t trigger onChanged
description: delete table rows doesn’t trigger onChanged
author: kreja
host: EXCEL
api_set: {}
script:
content: |
$("#create-table").click(createTable);
async function createTable() {
try {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const expensesTable = sheet.tables.add("A1:D1", true /*hasHeaders*/);
expensesTable.name = "ExpensesTable";
expensesTable.getHeaderRowRange().values = [["Date", "Merchant", "Category", "Amount"]];
expensesTable.rows.add(null /*add at the end*/, [
["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();
}
expensesTable.onChanged.add(async function () {
console.log('changed!');
});
sheet.activate();
await context.sync();
});
}
catch (error) {
OfficeHelpers.UI.notify(error);
OfficeHelpers.Utilities.log(error);
}
}
language: typescript
template:
content: |
<section class="ms-font-m">
<p>This sample shows how to create a table using the Excel JavaScript API.</p>
</section>
<section class="samples ms-font-m">
<h3>Try it out</h3>
<button id="create-table" class="ms-Button">
<span class="ms-Button-label">Create table</span>
</button>
</section>
language: html
style:
content: |
section.samples {
margin-top: 20px;
}
section.samples .ms-Button, section.setup .ms-Button {
display: block;
margin-bottom: 5px;
margin-left: 20px;
min-width: 80px;
}
language: css
libraries: |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
@types/office-js
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css
core-js@2.4.1/client/core.min.js
@types/core-js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts
jquery@3.1.1
@types/jquery@3.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment