Return str Excel column reference like 'BQ' for *column_number*. *column_number* is an int in the range 1-16384 inclusive, where 1 maps to column 'A'.
(column_number)
| 86 | |
| 87 | @staticmethod |
| 88 | def _column_reference(column_number): |
| 89 | """Return str Excel column reference like 'BQ' for *column_number*. |
| 90 | |
| 91 | *column_number* is an int in the range 1-16384 inclusive, where |
| 92 | 1 maps to column 'A'. |
| 93 | """ |
| 94 | if column_number < 1 or column_number > 16384: |
| 95 | raise ValueError("column_number must be in range 1-16384") |
| 96 | |
| 97 | # ---Work right-to-left, one order of magnitude at a time. Note there |
| 98 | # is no zero representation in Excel address scheme, so this is |
| 99 | # not just a conversion to base-26--- |
| 100 | |
| 101 | col_ref = "" |
| 102 | while column_number: |
| 103 | remainder = column_number % 26 |
| 104 | if remainder == 0: |
| 105 | remainder = 26 |
| 106 | |
| 107 | col_letter = chr(ord("A") + remainder - 1) |
| 108 | col_ref = col_letter + col_ref |
| 109 | |
| 110 | # ---Advance to next order of magnitude or terminate loop. The |
| 111 | # minus-one in this expression reflects the fact the next lower |
| 112 | # order of magnitude has a minumum value of 1 (not zero). This is |
| 113 | # essentially the complement to the "if it's 0 make it 26' step |
| 114 | # above.--- |
| 115 | column_number = (column_number - 1) // 26 |
| 116 | |
| 117 | return col_ref |
| 118 | |
| 119 | def _populate_worksheet(self, workbook, worksheet): |
| 120 | """ |
no outgoing calls