Example #1
0
        internal void ParseUnresolvedReference(Cell cell)
        {
            if (UnresolvedRangeReference.IsNullOrEmpty())
            {
                return;
            }
            Match             match;
            ParseArgumentType pat = FormulaParser.GetArgumentType(UnresolvedRangeReference, out match);
            Range             range;

            if (cell == null)
            {
                throw new ArgumentNullException("cell");
            }
            bool parsed = FormulaParser.ParseRange(cell, match, out range, pat == ParseArgumentType.AbsoluteRange);

            if (parsed)
            {
                UnresolvedRangeReference = "";
                CellFrom = range.CellFrom;
                CellTo   = range.CellTo;
            }
        }
Example #2
0
        private void ImportCell(XmlReader reader, Row row)
        {
            bool     isEmpty     = reader.IsEmptyElement;
            int      cellIndex   = row._Cells.Count;
            int      mergeDown   = 0;
            int      mergeAcross = 0;
            XmlStyle style       = null;
            string   formula     = "";
            string   reference   = "";

            foreach (XmlReaderAttributeItem xa in reader.GetAttributes())
            {
                if (xa.LocalName == "Index" && xa.HasValue)
                {
                    xa.Value.ParseToInt(out cellIndex);
                    cellIndex--;
                }
                if (xa.LocalName == "StyleID" && xa.HasValue)
                {
                    style = ParentBook.GetStyleByID(xa.Value);
                }
                if (xa.LocalName == "HRef" && xa.HasValue)
                {
                    reference = xa.Value;
                }
                if (xa.LocalName == "Formula" && xa.HasValue)
                {
                    formula = xa.Value;
                }
                if (xa.LocalName == "MergeAcross" && xa.HasValue)
                {
                    xa.Value.ParseToInt(out mergeAcross);
                }
                if (xa.LocalName == "MergeDown" && xa.HasValue)
                {
                    xa.Value.ParseToInt(out mergeDown);
                }
            }
            Cell cell = Cells(cellIndex, row.RowIndex);

            if (style != null)
            {
                cell.Style = style;
            }
            if (!reference.IsNullOrEmpty())
            {
                cell.HRef = reference;
            }
            if (!formula.IsNullOrEmpty())
            {
                FormulaParser.Parse(cell, formula);
                return;
            }
            if (isEmpty)
            {
                return;
            }
            if (mergeDown > 0 || mergeAcross > 0)
            {
                cell.MergeStart = true;
                Range range = new Range(cell, Cells(cellIndex + mergeAcross, row.RowIndex + mergeDown));
                _MergedCells.Add(range);
                cell.ColumnSpan = range.ColumnCount;
                cell.RowSpan    = range.RowCount;
            }
            while (reader.Read() && !(reader.Name == "Cell" && reader.NodeType == XmlNodeType.EndElement))
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "Data")
                    {
                        ImportCellData(reader, cell);
                    }
                    else if (reader.Name == "Comment")
                    {
                        ImportCellComment(reader, cell);
                    }
                }
            }
        }