Excel Column Name Generation Bug


The logic around converting column indexes and counds relies purely on a conversion between int and char. This works well when the column index is < 26, however as Excel would go to wrap to column AA, the CellName property returns '['. This bug is also present in the FiftyNine.Ag.OpenXML.Excel.Utilities.Formatting static class as the total size of the spreadsheet is determined.


Zelaskal wrote Feb 7, 2012 at 11:32 PM

A proposed solution would be to use logic such as this during the associated calls (the ColRowFormat static function and the CellName property):
        if (colIndex <= 25) return ((char)(colIndex + 65)).ToString();
            StringBuilder sb = new StringBuilder();
            sb.Append((char)(((colIndex / 26) - 1) + 65));
            sb.Append((char)(colIndex % 26 + 65));
            return sb.ToString();

wrote Feb 13, 2013 at 11:09 PM