1
Vote

Excel Column Name Generation Bug

description

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.

comments

Zelaskal wrote Feb 8, 2012 at 12:32 AM

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();
        else
        {
            StringBuilder sb = new StringBuilder();
            sb.Append((char)(((colIndex / 26) - 1) + 65));
            sb.Append((char)(colIndex % 26 + 65));
            return sb.ToString();
        }

wrote Feb 14, 2013 at 12:09 AM