private void ResolveNamedRangeReferences() { int printTitleIndex = -1; int i = -1; foreach (NamedRange nr in this.NamedRanges) { i++; if (nr.Name == "Print_Titles") { FormulaParser.ParsePrintHeaders(nr.Worksheet, nr.Range.UnresolvedRangeReference); printTitleIndex = i; } else { Worksheet ws = nr.Worksheet ?? this[0]; nr.Range.ParseUnresolvedReference(ws[0, 0]); if (nr.Name == "_FilterDatabase") { ws.AutoFilter = true; } if (nr.Name == "Print_Area") { ws.PrintArea = true; } } } if (printTitleIndex != -1) { this.NamedRanges.RemoveAt(printTitleIndex); } }
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.Empty; string reference = string.Empty; 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 = this.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 = this.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, this.Cells(cellIndex + mergeAcross, row.RowIndex + mergeDown)); this.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); } } } }