Возможность читать (и устанавливать) свойства документа с помощью Office.js недавно стала доступна как часть Набор требований к API ExcelApi 1.7. Этот набор требований в настоящее время находится в бета-версии, поэтому, чтобы использовать эту функцию API:
Вам потребуется ссылка на бета-версию CDN: https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
Если вы используете TypeScript, вам понадобится ссылка на файл beta d.ts: https://appsforoffice.microsoft.com/lib/beta/hosted/office.d.ts
Вы должны использовать достаточно новую сборку Excel (например, Office Insiders Fast). ). Если у вас недостаточно свежая сборка и вы пытаетесь использовать API свойств чтения документа, будет выдана ошибка ApiNotFound
.
В следующем фрагменте кода показаны свойства документа show to read (с использованием JavaScript):
Excel.run(function (context) {
var docProperties = context.workbook.properties;
// Load a combination of read-only
// and writeable document properties.
docProperties.load("author, lastAuthor, revisionNumber, title, subject, keywords, comments, category, manager, company, creationDate");
return context.sync()
.then(function () {
// Write the document properties to the console.
console.log("Author: " + docProperties.author);
console.log("Last author : " + docProperties.lastAuthor);
console.log("Revision number: " + docProperties.revisionNumber);
console.log("Title: " + docProperties.title);
console.log("Subject: " + docProperties.subject);
console.log("Keywords: " + docProperties.keywords);
console.log("Comments: " + docProperties.comments);
console.log("Category: " + docProperties.category);
console.log("Manager: " + docProperties.manager);
console.log("Company: " + docProperties.company);
console.log("Workbook creation date: " + docProperties.creationDate.toDateString());
});
}).catch(errorHandlerFunction);
А вот тот же фрагмент, но на TypeScript:
Excel.run(async (context) => {
let docProperties = context.workbook.properties;
// Load a combination of read-only
// and writeable document properties.
docProperties.load("author, lastAuthor, revisionNumber, title, subject, keywords, comments, category, manager, company, creationDate");
await context.sync();
// Write the document properties to the console.
console.log("Author: " + docProperties.author);
console.log("Last author : " + docProperties.lastAuthor);
console.log("Revision number: " + docProperties.revisionNumber);
console.log("Title: " + docProperties.title);
console.log("Subject: " + docProperties.subject);
console.log("Keywords: " + docProperties.keywords);
console.log("Comments: " + docProperties.comments);
console.log("Category: " + docProperties.category);
console.log("Manager: " + docProperties.manager);
console.log("Company: " + docProperties.company);
console.log("Workbook creation date: " + docProperties.creationDate.toDateString());
});
person
Kim Brandl
schedule
06.10.2017