OpenXML Read CustomXMLPart

Viewed 524

Hi I am trying to read through all the CustomXMLParts of some Excel files with the following Code but i cannot figure out how to get the xml Data of each individual part.

I cant seem to find the solution online anywhere

    public void getCustomXMLParts(string path){
        // Open the document for editing.
        int nCount = 0;
        using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(path, false)){
            // Code removed here.
            WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart;
            foreach (CustomXmlPart xmlPart in workbookPart.CustomXmlParts)
            {
                XmlDocument oDoc = new XmlDocument();
                //oDoc.Load();


                Response.Write("<Textarea cols=200 rows=10>"+ xmlPart.Uri + "</textarea>");
                nCount = nCount + 1;
            }
        }

        Response.Write("<BR>XML Parts Count=" + nCount);
    }

There is XML Data store in multiple XMLParts and i would just like to read the XML Part into my C# Code.

Thanks.

1 Answers

figured it out, had to use the following:

StreamReader reader = new StreamReader(xmlPart.GetStream(FileMode.Open, FileAccess.Read)); string FullXML = reader.ReadToEnd();

Related