0

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).

0

1 Answer 1

1

Unfortunately, the Document Service (Class DocumentApp) and the Advanced Docs Service can't support all the features that may be present in a document. The best might be to change your approach, and instead of replacing the content of the active document with the content of another document, you would just open the other document so it becomes the active document.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.