This article discusses troubleshooting issues that are unique to Word. Use the feedback tool at the end of the page to suggest other issues that can be added to this article.
All selected ranges aren't recognized
If noncontiguous selections are made, the Word API only operates on the last contiguous range in the selection. An unexpected case of this is when you select a column in a table then call, for example, Document.getSelection, only the final cell in the selection is returned by the API. Although the selection of a column seems contiguous, the API recognizes it as a noncontiguous selection (e.g., a cell per row).
Layout breaks when using insertHtml while cursor is in content control in header
This issue may occur when the following three conditions are met.
Have at least one content control in the header and at least one in the footer of the Word document.
Ensure the cursor is inside a content control in the header.
Call insertHtml to set a content control in the footer.
The footer is then unexpectedly mixed with the header. To avoid this, clear the content control in the footer before setting it, as shown in the following code sample.
await Word.run(async (context) => {
// Credit to https://github.com/barisbikmaz for this version of the workaround.
// For more information, see https://github.com/OfficeDev/office-js/issues/129.
// Let's say there are 2 content controls in the header and 1 in the footer.
const contentControls = context.document.contentControls;
contentControls.load();
await context.sync().then(function () {
// Clear the 2 content controls in the header.
contentControls.items[0].clear();
contentControls.items[1].clear();
// Clear the control control in the footer then update it.
contentControls.items[2].clear();
contentControls.items[2].insertHtml('<p>New Footer</p>', 'Replace');
});
});
Lost formatting of last bullet in a list or last paragraph
null has special implications in the Word JavaScript APIs. It's used to represent default values or no formatting.
Formatting properties such as color will contain null values in the response when different values exist in the specified range. For example, if you retrieve a range and load its range.font.color property:
If all text in the range has the same font color, range.font.color specifies that color.
If multiple font colors are present within the range, range.font.color is null.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Office Add-ins feedback
Office Add-ins is an open source project. Select a link to provide feedback: