Determines Excel worksheet layout and can write an Excel workbook from a CategoryChartData object. Serves as the authority for Excel worksheet ranges.
| 45 | |
| 46 | |
| 47 | class CategoryWorkbookWriter(_BaseWorkbookWriter): |
| 48 | """ |
| 49 | Determines Excel worksheet layout and can write an Excel workbook from |
| 50 | a CategoryChartData object. Serves as the authority for Excel worksheet |
| 51 | ranges. |
| 52 | """ |
| 53 | |
| 54 | @property |
| 55 | def categories_ref(self): |
| 56 | """ |
| 57 | The Excel worksheet reference to the categories for this chart (not |
| 58 | including the column heading). |
| 59 | """ |
| 60 | categories = self._chart_data.categories |
| 61 | if categories.depth == 0: |
| 62 | raise ValueError("chart data contains no categories") |
| 63 | right_col = chr(ord("A") + categories.depth - 1) |
| 64 | bottom_row = categories.leaf_count + 1 |
| 65 | return "Sheet1!$A$2:$%s$%d" % (right_col, bottom_row) |
| 66 | |
| 67 | def series_name_ref(self, series): |
| 68 | """ |
| 69 | Return the Excel worksheet reference to the cell containing the name |
| 70 | for *series*. This also serves as the column heading for the series |
| 71 | values. |
| 72 | """ |
| 73 | return "Sheet1!$%s$1" % self._series_col_letter(series) |
| 74 | |
| 75 | def values_ref(self, series): |
| 76 | """ |
| 77 | The Excel worksheet reference to the values for this series (not |
| 78 | including the column heading). |
| 79 | """ |
| 80 | return "Sheet1!${col_letter}$2:${col_letter}${bottom_row}".format( |
| 81 | **{ |
| 82 | "col_letter": self._series_col_letter(series), |
| 83 | "bottom_row": len(series) + 1, |
| 84 | } |
| 85 | ) |
| 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: |
no outgoing calls
searching dependent graphs…