none
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."

     

    2.how 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.

     

    Regards

    Vikas

         

     

    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.

     

    Regards,

    Kalpana

    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.

     

    Vikas

     

    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", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");

     

     

    xmlnsWorksheetNamespaceManager.addNamespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");

     

     

    Let me know if you want the full code.

     

    regards

    Kalpana

    Monday, September 15, 2008 2:24 PM