I am developing a Microsoft Word add-in using the JavaScript API, and I am encountering a problem when trying to import an external DOCX file into the current document. To achieve this, I converted the DOCX file to a Base64 format and used the following function:
const openExternalDocument = async () => {
await Word.run(async (context) => {
console.log("Opening external document...");
// Use the Base64-encoded string representation of the selected .docx file.
const externalDoc = context.application.createDocument(getDocumentAsBase64());
await context.sync();
const externalDocBody = externalDoc.body;
externalDocBody.load("text");
await context.sync();
// Insert the external document's text at the beginning of the current document's body.
const externalDocBodyText = externalDocBody.text;
const currentDocBody = context.document.body;
currentDocBody.insertText(externalDocBodyText, Word.InsertLocation.start);
await context.sync();
}).catch(function (myError) {
console.log("Error", myError);
});
};
While the document is successfully imported, I am facing an issue where all the text manipulation done in the external document is not visible in the current document. Any insights or suggestions on why this might be happening and how I can ensure the visibility of text manipulations from the external document in my Word add-in?
orginal document:
[imported document:
You didn't need to get text from
body
ofexternalDoc
when you get only text of this document andinsert
in your document text wasn't pick style.try this this will work 100%: insertfilefrombase64