none
Word - Change all content of a document RRS feed

  • Question

  • I am currently working on a VSTO addin which sends a document to a server side API (not in my control and cannot replicate functionality client side) and retrieve a modified version of the document as byte[].

    As there is no direct way to change all the content of a doc using a byte[], I thought of 4 possible options (the last being my preferred):

    1.        Save the document as a new document or overwrite current one – This is not ideal because Undo history is lost and it does not play very well with some bespoke DMS
    2.        Save to a hidden document and copy content onto the clipboard. Then update the document by pasting – this can work but I’m not sure it is a good idea to interact with the clipboard in such a way and undo action is labelled as Paste. Also, I am worried about loosing some styling/content...
    3.        Convert document to openxml and then use openxml sdk to change content – I didn’t try this but I have the feeling that forcing a conversion is not something I should do as it might affect some styling and not play well with other apps/addins
    4.        Use merge documents, accept all revisions, hide the review/revision pane and hide original document/revised document (ie. show only the combined result document) – this seems good however:
      1.          when this is done to an unsaved document, it works but the name of the doc changes from Document1 to Combine Result 1 – can this be changed?
      2.       Undo works but labels are named – Merge documents and VBA-Revisions.AcceptAll – can this be changed?
      3.        User can see original doc and styled doc by going into Review > Compare > Show source documents – can I stop this?

    Any other ideas? Am I right in thinking that option 4 is the best one?

    Thanks in advance, all feedback is truly appreciated.

    Leo

    Thursday, May 2, 2013 12:47 PM

Answers

  • Hi Leo

     I take it your problem has nothing to do with converting to/from byte[], but has more to do with reconciling the original content with what you're getting back from the server?

    What is it that needs to be changed in the document? I'm not clear why you wouldn't put the original document aside and use what's coming back from the server?

    Based on the little I know, my inclination would be to say option 3. Word Open XML is  what a *.docx file is - there is no difference. If you take your original file, put a .zip file extension on it, then look at the content, you can confirm this for yourself. Remove the extension and you're back to the original document. It should not affect styling nor have any side-effects with other applications or add-ins.

    As for option 4, there is no way to change any of the labels or the behavior of Compare Documents.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Lenny S Wednesday, May 15, 2013 8:31 AM
    Friday, May 3, 2013 8:03 AM
    Moderator

All replies

  • You also can use the new feature in Outlook 2013, There is Document.getFileAsync method to retrieve the word document as byte array, you only use the method to convert word document to byte array and then you can write byte array into filestream and save the word document on server.

    If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample

    Thursday, May 2, 2013 2:47 PM
  • Hi Leo

     I take it your problem has nothing to do with converting to/from byte[], but has more to do with reconciling the original content with what you're getting back from the server?

    What is it that needs to be changed in the document? I'm not clear why you wouldn't put the original document aside and use what's coming back from the server?

    Based on the little I know, my inclination would be to say option 3. Word Open XML is  what a *.docx file is - there is no difference. If you take your original file, put a .zip file extension on it, then look at the content, you can confirm this for yourself. Remove the extension and you're back to the original document. It should not affect styling nor have any side-effects with other applications or add-ins.

    As for option 4, there is no way to change any of the labels or the behavior of Compare Documents.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Lenny S Wednesday, May 15, 2013 8:31 AM
    Friday, May 3, 2013 8:03 AM
    Moderator