An Office service that supports add-ins to interact with objects in Office client applications.
Hi @Samardeep Mahur
From the information you provided, I understand that after insertFileFromBase64 completes, the Date Picker Content Control in the document header is not replaced.
After researching, it seems that currently the insertFileFromBase64 API in Office.js only replaces the body of the document, excluding the header, footer, or other parts of the document. That is also why the Date Picker Content Control (located in the header) remains the same as in the original document, even though your server-generated base64 file contains a Plain Text Content Control at the same position / same tag / same title.
When called on the body, insertFileFromBase64 maps directly to the body story of the document. In the OOXML structure, the header and footer are separate "stories". The API simply does not touch these stories, so the original Date Picker Content Control in the header remains intact.
Therefore, in this case, please refer to the new document-level API method (requires Word API 1.5), specifically Document.insertFileFromBase64:
await Word.run(async (context) => {
// Replace the entire document (body + headers + footers + sections)
context.document.insertFileFromBase64(
base64String,
Word.InsertLocation.replace,
{
// Optional but recommended – control what gets imported
importStyles: true,
importTheme: true,
importDifferentOddEvenPages: true, // if your header/footer uses this
// importPageSetup: true, // if you need margins/orientation etc.
}
);
await context.sync();
});
In addition, please refer the following documents:
Troubleshoot Word add-ins
Word.Document class
I hope the information I found helps clarify your scenario. Let me know if you need further details.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.