/// <summary> /// Adds numeric cell identifiers so that it is easier to work out position of cells /// Private method, for internal use only! /// </summary> private void AddNumericCellIDs() { // process each row foreach (XmlNode rowNode in WorksheetXml.SelectNodes("//d:sheetData/d:row", NameSpaceManager)) { // remove the spans attribute. Excel simply recreates it when the file is opened. XmlAttribute attr = (XmlAttribute)rowNode.Attributes.GetNamedItem("spans"); if (attr != null) { rowNode.Attributes.Remove(attr); } int row = Convert.ToInt32(rowNode.Attributes.GetNamedItem("r").Value); // process each cell in current row foreach (XmlNode colNode in rowNode.SelectNodes("./d:c", NameSpaceManager)) { XmlAttribute cellAddressAttr = (XmlAttribute)colNode.Attributes.GetNamedItem("r"); if (cellAddressAttr != null) { string cellAddress = cellAddressAttr.Value; int col = ExcelCell.GetColumnNumber(cellAddress); attr = WorksheetXml.CreateAttribute(tempColumnNumberTag); if (attr != null) { attr.Value = col.ToString(); colNode.Attributes.Append(attr); // remove all cell Addresses like A1, A2, A3 etc. colNode.Attributes.Remove(cellAddressAttr); } } } } }
/// <summary> /// Creates a ExcelWorkSheetDimension using a string with Cell Range representation like 'A1:B5'. /// </summary> /// <param name="dimension">a string with Cell Range representation like 'A1:B5'</param> public ExcelWorkSheetDimension(String dimension) { String[] dimensions = dimension.Split(':'); this.topLeft = dimensions[0]; this.bottomRight = dimensions[1]; if (!ExcelCell.IsValidCellAddress(topLeft) || (!ExcelCell.IsValidCellAddress(BottomRight))) { throw new ArgumentException("No valid excel sheet dimension!"); } firstRow = ExcelCell.GetRowNumber(topLeft); firstCol = ExcelCell.GetColumnNumber(topLeft); lastCol = ExcelCell.GetColumnNumber(bottomRight); lastRow = ExcelCell.GetRowNumber(bottomRight); }