Example #1
0
        /// <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(XmlDocument worksheetDoc)
        {
            // process each row
            foreach (XmlNode rowNode in worksheetDoc.SelectNodes("//d:sheetData/d:row", NameSpaceManager))
            {
                // remove the spans attribute.  Excel simply recreates it when the file is opened.
                var 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))
                {
                    var cellAddressAttr = (XmlAttribute)colNode.Attributes.GetNamedItem("r");
                    if (cellAddressAttr != null)
                    {
                        var cellAddress = cellAddressAttr.Value;

                        var col = ExcelCell.GetColumnNumber(cellAddress);
                        attr = worksheetDoc.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);
                        }
                    }
                }
            }
        }