Esempio 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());
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
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());
        }