In this article I will demonstrate and discuss how to programmatically save a Word document directly into Salesforce.
Turning your word document into a binary
This article in the Office dev center details how to Get the whole document from an add-in for PowerPoint or Word. We will use the bulk of that article up to the point where we send the slice. We are going to look at a modified sendSlice() function. The dev.office.com article details how you can access the binary contents of the word document, but falls short when it comes to getting the base64 encoded version of the file to be submitted to an external site. This is the complicated part !
Getting the right format for Salesforce
Using the code posted on this stackoverflow post we are able to turn a binary string into the necessary format to send the file to salesforce.
The final sendSlice() function is shown below. The significant thing to note is that the initial file must be sent to the ContentVersion sobject. Because this is a new document a parentId is not necessary and a ContentDocumentId is created. In a future article we will look at how to then associate this new file attachment is an existing object.
In this article we have seen an example of how we can extend the functionality of an Office Add-In to access the binary data of a word document and then save it to a cloud provider (in this case Salesforce).
4 thoughts on “Saving a word document directly from an Office Add-In into Salesforce.com”
Hi Mark, I am trying to use this same approach to save a document to a different 3rd party document management system (NetDocuments) from Office 365 and am struggling with this add-in model. Can’t even seem to get the vanilla Microsoft example to work (https://dev.office.com/docs/add-ins/develop/get-the-whole-document-from-an-add-in-for-powerpoint-or-word) Would you happen to have a sample of the complete solution (without the second piece of SalesForce) that I could use to see where we are going wrong? Any pointers are appreciated. // David
David – currently on vacation
Will get back to you in a bit 🙂
I am following this thread and we are trying to upload large word files and import large size files from Nextcloud and other web applications we have developed.
The current method we are using is uploading the documents in chunks. The issue with this is if the file contains tables, images, figures and other styled content; the document content and indentations get distorted.
Is there a better way to import large files from 3rd party applications and also uploading documents to 3rd party applications from word add-in?
Someone suggested using insertbase64 but I would appreciate getting a solid approach on this.
Thanks in Advance!
Sorry mate – this article is 6 years old and I no longer work in this area, so I am unable to provide good guidance. Good luck in solving your issues