public SheetWithoutHDR(ulong Id, string XmlSource, ExcelStream Excel, SharedStrings stringDictionary)
            : base(Id, Excel, stringDictionary)
        {
            var xd = new XmlDocument();

            xd.LoadXml(XmlSource);
            var rows = xd.GetElementsByTagName("row");

            // 遍历row标签
            foreach (XmlNode x in rows)
            {
                var cols = x.ChildNodes;
                var objs = new Row();
                // 遍历c标签
                foreach (XmlNode y in cols)
                {
                    string value = null;
                    // 如果是字符串类型,则需要从字典中查询
                    if (y.Attributes["t"]?.Value == "s")
                    {
                        var index = Convert.ToUInt64(y.FirstChild.InnerText);
                        value = StringDictionary[index];
                    }
                    else if (y.Attributes["t"]?.Value == "inlineStr")
                    {
                        value = y.FirstChild.FirstChild.InnerText;
                    }
                    // 否则其中的v标签值即为单元格内容
                    else
                    {
                        value = y.InnerText;
                    }

                    objs.Add(value, y.Attributes["r"].Value);
                }

                // 去掉末尾的null
                while (objs.LastOrDefault() == null)
                {
                    objs.RemoveAt(objs.Count - 1);
                }
                if (objs.Count > 0)
                {
                    this.Add(objs);
                }
            }
            while (this.Count > 0 && this.Last().Count == 0)
            {
                this.RemoveAt(this.Count - 1);
            }
            GC.Collect();
        }
Пример #2
0
        public SheetReader(Stream sheetStream, SharedStrings sharedStrings, bool hdr)
        {
            _sheetStream   = sheetStream;
            _sharedStrings = sharedStrings;
            _hdr           = hdr;

            _xmlReader = XmlReader.Create(sheetStream);

            if (!_xmlReader.ReadToFollowing("sheetData") || !_xmlReader.ReadToFollowing("row"))
            {
                throw new NotSupportedException("Not expected file-format");
            }

            if (hdr)
            {
                Header = ReadNextRow();
            }
            if (Header == null)
            {
                Header = new Header();
            }
        }
Пример #3
0
 public Sheet(ulong Id, ExcelStream Excel, SharedStrings StringDictionary)
 {
     this.Id = Id;
     this.StringDictionary = StringDictionary;
     this.excel            = Excel;
 }
Пример #4
0
 public Sheet(ulong id, ExcelStream excel, SharedStrings stringDictionary)
 {
     _id              = id;
     _excel           = excel;
     StringDictionary = stringDictionary;
 }