5
Làm cách nào để chuyển đổi một số XElement
thành OpenXmlElement
? Hoặc là Google-fu của tôi không thành công hoặc điều này chưa được giải quyết.OpenXml: Chuyển đổi XElement thành OpenXmlElement
Làm cách nào để chuyển đổi một số XElement
thành OpenXmlElement
? Hoặc là Google-fu của tôi không thành công hoặc điều này chưa được giải quyết.OpenXml: Chuyển đổi XElement thành OpenXmlElement
Bạn có thể chuyển đổi một OpenXmlElement
trao cho một XElement
sử dụng đoạn mã sau:
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);
Để chuyển đổi một XElement để một OpenXmlElement thử đoạn mã sau:
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();
}
Hope, điều này sẽ giúp.