Created
August 4, 2022 06:12
-
-
Save xuruiyao-msft/f4de3373aefca3764b46581e4b97a40d to your computer and use it in GitHub Desktop.
Create a new snippet from a blank template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: FootEndNote (1) | |
description: Create a new snippet from a blank template. | |
host: WORD | |
api_set: {} | |
script: | |
content: | | |
OfficeExtension.config.extendedErrorLogging = true; | |
$("#run").click(() => tryCatch(run)); | |
$("#getFirst").click(() => tryCatch(getFirst)); | |
$("#items").click(() => tryCatch(items)); | |
$("#getFirstOrNull").click(() => tryCatch(getFirstOrNull)); | |
$("#next").click(() => tryCatch(next)); | |
$('#body').click(()=>tryCatch(body)); | |
async function body() { | |
await Word.run(async (context) => { | |
const body = context.document.body; | |
const endnotes = body.endnotes; | |
endnotes.load(); | |
await context.sync(); | |
let first = endnotes.getFirstOrNullObject(); | |
first.load(); | |
let fBody = first.body; | |
fBody.load(); | |
await context.sync(); | |
console.log("firstbody:" + fBody.text); | |
//paragraphs | |
let paragraphs = fBody.paragraphs; | |
paragraphs.load(); | |
await context.sync(); | |
let fp = paragraphs.items[0]; | |
fp.load(); | |
await context.sync(); | |
console.log("first paragraph:" + fp.text); | |
}) | |
} | |
async function next() { | |
await Word.run(async (context) => { | |
const body = context.document.body; | |
const endnotes = body.endnotes; | |
endnotes.load(); | |
await context.sync(); | |
let first = endnotes.getFirstOrNullObject(); | |
first.load(); | |
await context.sync(); | |
console.log("first type:" + first.type); | |
let next = first.getNext(); | |
next.load(); | |
let nextbody = next.body; | |
nextbody.load(); | |
await context.sync(); | |
console.log("next text:" + nextbody.text); | |
}); | |
} | |
async function getFirstOrNull() { | |
await Word.run(async (context) => { | |
const body = context.document.body; | |
const endnotes = body.endnotes; | |
endnotes.load(); | |
await context.sync(); | |
let first = endnotes.getFirstOrNullObject(); | |
first.load(); | |
await context.sync(); | |
console.log("first endnote:" + first); | |
let firstbody = first.body; | |
firstbody.load(); | |
await context.sync(); | |
console.log("first endnote text:" + firstbody.text); | |
}); | |
} | |
async function items() { | |
await Word.run(async (context) => { | |
const body = context.document.body; | |
const endnotes = body.endnotes; | |
endnotes.load(); | |
await context.sync(); | |
const endnote1 = endnotes.items[0]; | |
endnote1.load(); | |
await context.sync(); | |
console.log("endnote1:" + endnote1.type); | |
endnote1.delete(); | |
await context.sync(); | |
}); | |
} | |
async function run() { | |
await Word.run(async (context) => { | |
// const body = context.document.getFootnoteBody(); | |
// body.load(); | |
// await context.sync(); | |
const range = context.document.getSelection(); | |
// let footnote = range.insertFootnote("222"); | |
let endnote = range.insertEndnote("endnote"); | |
// footnote.load(); | |
endnote.load(); | |
await context.sync(); | |
// console.log("type: "+ footnote.type); | |
console.log("endnote type: " + endnote.type); | |
let endnoteRange = endnote.body.getRange(); | |
endnoteRange.load(); | |
await context.sync(); | |
console.log("endnote body.range.text: " + endnoteRange.text); | |
let body = endnote.body; | |
body.load(); | |
await context.sync(); | |
// body.insertContentControl(); | |
await context.sync(); | |
console.log("body text: " + body.text); | |
// console.log("body type: " + body.type); | |
// // const body = context.document.body; | |
// // body.load(); | |
// // await context.sync(); | |
// const footnotes = body.footnotes; | |
// footnotes.load("item"); | |
// await context.sync(); | |
// console.log("footnotes length: " + footnotes.items.length); | |
// const footnote = footnotes.items[0]; | |
// footnote.load(); | |
// const ref = footnote.reference; | |
// ref.load(); | |
// await context.sync(); | |
// ref.select(); | |
// console.log("footnote reference text: " + ref.text); | |
// const fn = footnotes.items[0]; | |
// fn.load("type"); | |
// await context.sync(); | |
// console.log("footnote type: "+ fn.type); | |
// const comments = context.document.body.getComments(); | |
// comments.load(); | |
// await context.sync(); | |
// console.log("comments length: " + comments.items.length); | |
// const comment = comments.items[0]; | |
// comment.load(); | |
// await context.sync(); | |
// console.log("comment type: " + comment.creationDate); | |
// const sections = context.document.sections; | |
// sections.load(); | |
// await context.sync(); | |
// console.log("section 1: "+ sections.items[0]); | |
// console.log("section 2: "+ sections.items[1]); | |
}); | |
} | |
async function getFirst() { | |
await Word.run(async (context) => { | |
const body = context.document.body; | |
body.load(); | |
await context.sync(); | |
let endnotes = body.endnotes; | |
endnotes.load(); | |
await context.sync(); | |
let endnote = endnotes.getFirst(); | |
endnote.load(); | |
let endnoteBody = endnote.body; | |
endnoteBody.load(); | |
await context.sync(); | |
console.log("endnoteBody.text:" + endnoteBody.text); | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
async function tryCatch(callback) { | |
try { | |
await callback(); | |
} catch (error) { | |
// Note: In a production add-in, you'd want to notify the user through your add-in's UI. | |
console.error(error); | |
} | |
} | |
language: typescript | |
template: | |
content: |- | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
<button id="items" class="ms-Button"> | |
<span class="ms-Button-label">items</span> | |
</button> | |
<button id="getFirst" class="ms-Button"> | |
<span class="ms-Button-label">getFirst</span> | |
</button> | |
<button id="getFirstOrNull" class="ms-Button"> | |
<span class="ms-Button-label">getFirstOrNull</span> | |
</button> | |
<button id="next" class="ms-Button"> | |
<span class="ms-Button-label">next</span> | |
</button> | |
<button id="nextOrNull" class="ms-Button"> | |
<span class="ms-Button-label">nextOrNull</span> | |
</button> | |
<button id="body" class="ms-Button"> | |
<span class="ms-Button-label">body</span> | |
</button> | |
<button id="footNoteBody" class="ms-Button"> | |
<span class="ms-Button-label">footNoteBody</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