Ejemplo n.º 1
0
        /// <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());
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 /// <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;
         }
     }
 }
Ejemplo n.º 5
0
        /// <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());
        }
Ejemplo n.º 6
0
        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);
        }