从doc文件中我正在阅读来自https://msdn.microsoft.com/en-us/library/ee413542(v=office.12).aspx引用的doc标题。我能够获得标题的OOXML,但是我无法使用Office 365 add in将其插入到我的在线单词中。 请帮我在完整的文档ooxml中插入标题。
此致 普利文
答案 0 :(得分:0)
找到了在word文档中插入标题的示例
function insertHeader() {
Word.run(function (context) {
var myHeader = context.document.sections.getFirst()
.getHeader("primary").insertText("This is a header", "start");
return context.sync();
}).catch(function(error) {
console.log(error);
});
}
function insertFooter() {
Word.run(function (ctx) {
// Create a proxy collection for the sections collection.
var mySections = ctx.document.sections;
// Queue a command to load style property of the sections.
ctx.load(mySections, 'body/style');
// Synchronize the document state by executing the queued commands,
// and returning a promise to indicate task completion.
return ctx.sync().then(function () {
// Get the primary footer of the first section and create
// a proxy Body object for the footer.
var myFooter = mySections.items[0].getFooter("primary");
// Queue a command to insert a paragraph at the end of the footer.
myFooter.insertParagraph("Confidential", "end");
// Queue a command to insert a line break at the end of the footer.
myFooter.insertBreak("line", "end");
})
// Synchronize the document state by executing the queued commands.
.then(ctx.sync)
.then(function () {
handleSuccess();
})
.catch(function (error) {
handleError(error);
})
});
}