none
Saving Embedded Excel object to drives RRS feed

  • Question

  • Hi,

     

    I have a XML file embedded in a Excel workbook(i.e. added through  Shapes-> Add object).

     

    Now through my VSTO Add-in I want to store that XML file to a specific location in my drives.

     

    I am able to retrive all my OLE objetc from Excel through 

     Excel.OLEObjects aobj = (Excel.OLEObjects)objSheet.OLEObjects(Type.Missing);

     

    Can anyone please help me out on ways to save the XML file in my drives

     

    Thanks


    Friday, May 27, 2011 9:07 AM

Answers

  • Hi VG

    2007/2010, that's very good :-)

    These versions have the concept of a "Custom XML Part". An xlsx file is basically a "zipped package" of XML files. Using the standard Packaging and XML namespaces of the .NET Framework, you can work with the closed files. And one of the things this file format allows you to do is include other XML files within the "package", as Custom XML Parts.

    Custom XML Parts can also be accessed at run-time, through the object model (Workbook.CustomXMLParts).

    So you have the option of including/extracting your XML from the closed file, or at run-time.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bruce Song Tuesday, June 7, 2011 12:56 PM
    Tuesday, May 31, 2011 8:39 AM
    Moderator

All replies

  • Hi VG

    Whether this is possible is going to depend on whether there's a program installed on the machine that's able to handle the XML file as an OLE Server. In order to work with an embedded file in the object model the file must be opened in a program that can work with the file and also provides an automation interface (API) that Excel can communicate with.

    If, for example, you embed a Word file in Excel, then the embedded file can be opened in Word and saved through Word's automation interface as a separate file.

    Is such a program available on the machines to which you plan to deploy your add-in? If not, you probably need to re-think how you want to do whatever functionality you want to provide.

    Which version(s) of Excel are we dealing with, here? What is it you need to do with this XML file (besides just saving it)?


    Cindy Meister, VSTO/Word MVP
    Monday, May 30, 2011 7:49 AM
    Moderator
  • Hi,

     

    We are basically dealing with excel version 2007 and Excel 2010.

    I don't think that at the client end there would be program installed that will be able to handle XML file as an OLE Server.Through presence of notepad/IE can be guaranteed.

     

    I plan to add a XML file as an OLE object through a rich client application and access the same through VSTO Add-in.

    I am able to successfully embed the XML file as OLE object and m also able to retrieve the same as OLE object but I need to same the XML to some location (even reading/loading the same as XML Document will be great).

     

    Actually I am embedding an object of a serialize-able class as XML in Excel sheet and wist to repopulate that object through VSTO Add-in.Can you suggest any other approach for the same.

     

    Thanks

     

    Tuesday, May 31, 2011 8:07 AM
  • Hi VG

    2007/2010, that's very good :-)

    These versions have the concept of a "Custom XML Part". An xlsx file is basically a "zipped package" of XML files. Using the standard Packaging and XML namespaces of the .NET Framework, you can work with the closed files. And one of the things this file format allows you to do is include other XML files within the "package", as Custom XML Parts.

    Custom XML Parts can also be accessed at run-time, through the object model (Workbook.CustomXMLParts).

    So you have the option of including/extracting your XML from the closed file, or at run-time.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bruce Song Tuesday, June 7, 2011 12:56 PM
    Tuesday, May 31, 2011 8:39 AM
    Moderator
  • Hi,

     

    Thanks a lot for your help.

     

    Can you please provide me a link to an example to achieve this.

     

     

    Friday, June 3, 2011 8:45 AM
  • Which? Working with Custom XML Parts using Word Open XML? Or through the object model?

    For the first, start at OpenXMLDeveloper.org, then ask questions in the Open XML SDK forum.

    For the second a search on MSDN returns a number of useful articles:
    http://social.msdn.microsoft.com/search/en-US?query=%22CustomXMLPart%22%20Excel&refinement=117


    Cindy Meister, VSTO/Word MVP
    Friday, June 3, 2011 9:33 AM
    Moderator