2011-12-07 72 views

回答

8

您可以使用下面的代碼轉換給定OpenXmlElementXElement

OpenXmlElement el = ...; // Code to get the xml element from your office doc. 

// Then use XElement.Parse and the OuterXml property. 
XElement xel = XElement.Parse(el.OuterXml); 

要一個的XElement轉換爲OpenXmlElement試試下面的代碼:

XElement xe = ...; 
using(StreamWriter sw = new StreamWriter(new MemoryStream())) 
{ 
    sw.Write(xe.ToString()); 
    sw.Flush(); 
    sw.BaseStream.Seek(0, SeekOrigin.Begin); 

    OpenXmlReader re = OpenXmlReader.Create(sw.BaseStream); 

    re.Read(); 
    OpenXmlElement oxe = re.LoadCurrentElement(); 
    re.Close(); 
} 

希望,這會有所幫助。

相關問題