2
我想要在任務窗格應用程序中使用office js API將頁眉和頁腳插入到文檔中。我似乎找不到添加頁眉和頁腳到文檔的方法。插入頁眉和頁腳office.js api
我想要在任務窗格應用程序中使用office js API將頁眉和頁腳插入到文檔中。我似乎找不到添加頁眉和頁腳到文檔的方法。插入頁眉和頁腳office.js api
頁眉和頁腳繼承Body類,可通過初始化Section來訪問。這裏是Office-JS Snippet Explorer的sample:
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy sectionsCollection object.
var mySections = context.document.sections;
// Queue a commmand to load the sections.
context.load(mySections, 'body/style');
// Synchronize the document state by executing the queued-up commands,
// and return a promise to indicate task completion.
return context.sync().then(function() {
// Create a proxy object the primary header of the first section.
// Note that the header is a body object.
var myHeader = mySections.items[0].getHeader("primary");
// Queue a command to insert text at the end of the header.
myHeader.insertText("This is a header.", Word.InsertLocation.end);
// Queue a command to wrap the header in a content control.
myHeader.insertContentControl();
// Synchronize the document state by executing the queued-up commands,
// and return a promise to indicate task completion.
return context.sync().then(function() {
console.log("Added a header to the first section.");
});
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
context.document.sections在API中不存在。這段代碼拋出。 –
您使用的是哪個版本的Word? –
我看到此功能僅適用於Office 2016桌面(&iPad) - 是否有計劃何時進入Office Online? – lgaud