How to write the values(number/string) in the defined cells using OPENXMLformat SDK RRS feed

  • Question


    HI ,


    I am Playing with OpenXML.


    I have an issue to write the strings in cells.

    name of the cell has been defined by the user.


    here 2 problem i am facing

    1.After writting any string to the cell, i am able to write the strings in cell comfortably but when i am trying to open the saved XLSM file it says that "converter failed to open the file."

  i can write the values(number/string) in the cells for that name has been defined by user.



    Another issue is how to delete a sheet using OPEN XML API if the sheet is keeping the relationship with other sheets.

    i am able to delete the sheet if that sheet is not having any relationship.



    Any help or tips is greatly appreciated.






    Thursday, August 21, 2008 4:14 PM

All replies


    Hi Vikas,


    What do you mean by defined cells? Give me more information.. le tme see if I can help.




    Tuesday, September 9, 2008 9:39 PM
  • Dear Kalpana,


    Defined cells means that you can give your own name to a cell or cell Range similar to a macroname or function name.




    Monday, September 15, 2008 6:30 AM

    Hi Vikas,


    All defined cell entries are entered in the workbook.xml irrespective of their scope.  (workbook/definedNames/definedName node)

    You can get the range or the defined cell ID, and parse the Cell address(es).

    Using those address you can use XPath


    XmlNode xmlnodeCell = xmlSheet1Document.selectSingleNode("//d:worksheet/dTongue TiedheetData/d:row/d:cell[@r=' + cellAddress + ']', xmlnsWorksheetNamespaceManager);


    (xmlSheet1Document is the XmlDocument object reference by extracting the Sheet Part from the workbook.)


    using the xmlnodeCell object pull out the stylesheet index, and using the stylesheet document get the "xf" node of the cellXfs parent node in a similar fashion...


    This is the way I know of pulling out cell details if you know the cell address.



    Construct the namespace Manager object like this:

    (do this after you have initialised the xmldocSheet1Document and loaded it with the corresponding sheetpart's xml stream)

    XmlNamespaceManager xmlnsWorksheetNamespaceManager = new XmlNamespaceManager(xmldocSheet1Document. NameTable);


    xmlnsWorksheetNamespaceManager.addNamespace("d", "");



    xmlnsWorksheetNamespaceManager.addNamespace("r", "");



    Let me know if you want the full code.




    Monday, September 15, 2008 2:24 PM