Word
A family of Microsoft word processing software products for creating web, email, and print documents.
901 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am trying to add a quote
field using the JS API for Word Add-ins:
export const insertQuoteField = async (str) => {
try {
Word.run(async (context) => {
const range = context.document.getSelection();
// Define the field type and field code
const location = Word.InsertLocation.replace
const fieldType = Word.FieldType.quote;
// Insert the field at the current selection
range.insertField(location, fieldType, `${str}`);
// Sync the context to ensure everything is updated in the document
await context.sync();
});
} catch (error) {
console.error("Error inserting QUOTE field:", error);
}
};
This works so far, except that if str
contains spaces, the spaces are not displayed. However, if I edit the field, the spaces are there, and they appear when I click save. But I have not been able to get the spaces to display programmatically without user interaction.
Has anyone encountered this issue? Is there a way to programmatically trigger the field to update and display spaces without requiring user interaction?