Change presentation XML of an open document RRS feed

  • Question

  • Is it possible to change the presentation XML of an open Excel file to create a new worksheet from SpreadsheetML?

    Monday, June 4, 2007 9:30 PM

All replies

  • Hi Johan,


    I don't think I quite get the question. What is it that you are trying to achieve? Create a new worksheet in SpreadsheetML? How does the 'presentation XML' come into play? And what do you mean by 'presentation XML'?


    Let me know and I'll try and help,



    Tuesday, June 5, 2007 9:16 AM
  • Thank you for your reply.


    I'll try to explain better. Smile


    I really like working with XML and XSLT and think that for generating documents and spreadsheets XML and XSLT is much better than using the object model. Better separation of code and presentation. With new new document formats it's easy to create new document and spreadsheets using XML and the new API for the new file formats. But what if I'm already in a VSTO solution and would like to change or add content to a document or spreadsheet? Word has a method for injecting WordML in the document, but Excel does not.


    So my question is if there are ways to create new worksheets or change existing sheets using SpreadsheetML in an open document? For instance to transform XML data into SpreadsheetML and append it to the document. Is it possible to modify parts of the package while the file is open?



    Tuesday, June 5, 2007 10:27 AM
  • Hi Johan,

    I think the answer to the question (of whether an app could modify the parts of the package while the file is open) really depends on the mode in which file is opened. In general, if one app (be it word or Visual studio) opens the file with exclusive write access, other apps could not save to the same tile. And I think WORD actually does just that — it opens the tile with exclusive write access. User could implement an app without especially holding the write access to the file from the very beginning till the end. Such app tries to open the file with write-access only when user wants to save to the file and it releases the access after saving is done. I know some tool apps do that.

    This SDK API allows user to open the package with different mode. User could choose different mode based on their requirements. And write-access is released when the document is closed/disposed.


    Hope this helps.


    Monday, June 25, 2007 9:20 AM
  • Hi Johan, Lanqing,


    no, you cannot change a file on disk while it's open in an editor (usually). The reason for this is that a document is loaded into memory, the file is left alone untill the user saves. If you would change the file on disk and the editor reloads the document, the user would either lose his changes, or get a difficult question about whether his document should reload (which he doesn't understand because he didn't change it). Office locks the file on disc to prevent such actions and resulting difficulties from occuring.

    Then the question is does the editor (Word, Excel) allow you to work with Open XML markup through their API. The answer is mostly, no they do not. As soon as the document loads there is no Open XML. The in memory structures are application specific. The old binary format serialized these objects to improve loading time, now that we have Open XML the in memory representation is converted between objects and Open XML. The Word functions for inserting and retrieving Open XML markup to this conversion for a small part of the document, similar to loading / saving. They are not fully Open XML capable, you cannot use an XPath query to select a node for instance, or access package parts outside of the Custom XML parts.


    Hope this helps,




    ps, most also do not really need this as their code can work against the application object model.

    Wednesday, June 27, 2007 6:19 PM