Skip to content

Instantly share code, notes, and snippets.

@chenxizhang
Created September 4, 2022 09:19
Show Gist options
  • Select an option

  • Save chenxizhang/43554fddae51603d8ed7769776acdc97 to your computer and use it in GitHub Desktop.

Select an option

Save chenxizhang/43554fddae51603d8ed7769776acdc97 to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
name: 读取文档基本信息
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run(async (context) => {
const wb = context.workbook;
const sheet = wb.worksheets.getActiveWorksheet();
const properties = wb.properties;
wb.load("name");
properties.load(["name", "author", "lastAuthor", "title", "category", "comments", "company", "subject"]);
await context.sync();
const data = [
["文件名", context.workbook.name],
["作者", properties.author],
["最后修改人", properties.lastAuthor],
["标题", properties.title],
["类别", properties.category],
["备注", properties.comments],
["公司", properties.company],
["主题", properties.subject]
];
sheet.getRange("A1").getResizedRange(data.length - 1, 1).values = data;
sheet
.getUsedRange()
.getEntireColumn()
.format.autofitColumns();
await context.sync();
});
}
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
console.error(error);
}
}
language: typescript
template:
content: |
<button id="run" class="ms-Button">
<span class="ms-Button-label">Run</span>
</button>
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
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