/// <summary> /// Copy&Modify from ExcelDataReader @MIT License /// </summary> public static string ReadStringItem(XmlReader reader) { var result = new StringBuilder(); if (!XmlReaderHelper.ReadFirstContent(reader)) { return(string.Empty); } while (!reader.EOF) { if (XmlReaderHelper.IsStartElement(reader, "t", _ns)) { // There are multiple <t> in a <si>. Concatenate <t> within an <si>. result.Append(reader.ReadElementContentAsString()); } else if (XmlReaderHelper.IsStartElement(reader, "r", _ns)) { result.Append(ReadRichTextRun(reader)); } else if (!XmlReaderHelper.SkipContent(reader)) { break; } } return(result.ToString()); }
public static string ReadStringItem(XmlReader reader) { string result = string.Empty; if (!XmlReaderHelper.ReadFirstContent(reader)) { return(result); } while (!reader.EOF) { if (reader.IsStartElement("t", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")) { // There are multiple <t> in a <si>. Concatenate <t> within an <si>. result += reader.ReadElementContentAsString(); } else if (reader.IsStartElement("r", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")) { result += ReadRichTextRun(reader); } else if (!XmlReaderHelper.SkipContent(reader)) { break; } } return(result); }
public static IEnumerable <string> GetSharedStrings(Stream stream, params string[] nss) { using (var reader = XmlReader.Create(stream)) { if (!XmlReaderHelper.IsStartElement(reader, "sst", nss)) { yield break; } if (!XmlReaderHelper.ReadFirstContent(reader)) { yield break; } while (!reader.EOF) { if (XmlReaderHelper.IsStartElement(reader, "si", nss)) { var value = StringHelper.ReadStringItem(reader); yield return(value); } else if (!XmlReaderHelper.SkipContent(reader)) { break; } } } }
/// <summary> /// e.g skip row 1 to row 2 /// </summary> /// <param name="reader"></param> public static void SkipToNextSameLevelDom(XmlReader reader) { while (!reader.EOF) { if (!XmlReaderHelper.SkipContent(reader)) { break; } } }
/// <summary> /// Copy&Modify from ExcelDataReader @MIT License /// </summary> private static string ReadRichTextRun(XmlReader reader) { var result = new StringBuilder(); if (!XmlReaderHelper.ReadFirstContent(reader)) { return(string.Empty); } while (!reader.EOF) { if (XmlReaderHelper.IsStartElement(reader, "t", _ns)) { result.Append(reader.ReadElementContentAsString()); } else if (!XmlReaderHelper.SkipContent(reader)) { break; } } return(result.ToString()); }
private static string ReadRichTextRun(XmlReader reader) { string result = string.Empty; if (!XmlReaderHelper.ReadFirstContent(reader)) { return(result); } while (!reader.EOF) { if (reader.IsStartElement("t", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")) { result += reader.ReadElementContentAsString(); } else if (!XmlReaderHelper.SkipContent(reader)) { break; } } return(result); }