I’m building a Google Docs add-on using React + Google Apps Script (via clasp). From the sidebar, I receive a .docx file as a Base64 string (binary content).
I can successfully convert the .docx to a Google Doc using the Drive API — that part works fine. Here’s my Apps Script function:
function insertDocxToDocument(base64Data) {
const decoded = Utilities.base64Decode(base64Data);
const blob = Utilities.newBlob(
decoded,
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'converted.docx'
);
const file = Drive.Files.insert(
{
title: 'Converted from DOCX',
mimeType: 'application/vnd.google-apps.document',
},
blob
);
return 'https://docs.google.com/document/d/' + file.id + '/edit';
}
This returns the link to the converted Google Doc, and when I open that URL, it looks perfect — all formatting and content are intact.
However, what I actually want is to load that converted document into the same Google Doc that my add-on is currently open in (basically replace the current document’s entire content with the new one).