-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
page number #2111
Comments
Hi @XWANG0224, Thank you for the questions. @ElizabethSamuel-MSFT, are these scenarios supported in the Word API at this time? |
@XWANG0224 Thanks for your question. For a dynamic solution, you can use the Page field. For example, the following code inserts a page field before the selected text in the document. The user should see the number of the current page if the field is set to show the result instead of the code. async function rangeInsertPageField() {
// Inserts a Page field before selection.
await Word.run(async (context) => {
const range: Word.Range = context.document.getSelection().getRange();
const field: Word.Field = range.insertField(
Word.InsertLocation.before,
Word.FieldType.page
);
field.load("result,code");
await context.sync();
if (field.isNullObject) {
console.log("There are no fields in this document.");
} else {
console.log("Code of the field: " + field.code, "Result of the field: " + JSON.stringify(field.result));
}
});
} Console logs In this case, I'd selected text on the second page of my document.
In Script Lab, you can use the Manage fields sample to experiment with the JS field APIs. You can try something like the following to insert the Page field in the footer. async function addFooter() {
await Word.run(async (context) => {
context.document.sections
.getFirst()
.getFooter("Primary")
.insertText(
"",
Word.InsertLocation.replace)
.getRange()
.insertField(
Word.InsertLocation.replace,
Word.FieldType.page
);
await context.sync();
});
} In Script Lab, you can use the Insert headers and footers sample to experiment with header/footer APIs. For more about the Page field, see Field codes: Page field. For more about fields in general, see Insert, edit, and view fields in Word. Note that the client/platform availability of the Page field depends on if it's supported in the Word UI on that client/platform. Let us know if this helps or if you have further questions. Thanks. |
@XWANG0224 Thanks for letting us know that my response helped. As for the cross-reference field showing the code instead of the result, try the following in the Word UI.
Instead of seeing the field's code, you should now see the results - As for using the ref field in your add-in code, you should be able to adapt the For more about the Ref field, see Field codes: Ref field. Hope this helps. |
is there any way I can get the page number where a selected paragraph is loacated?
and is there any way I can add the page number into the footer
The text was updated successfully, but these errors were encountered: