Determines Excel worksheet layout and can write an Excel workbook from XY chart data. Serves as the authority for Excel worksheet ranges.
| 176 | |
| 177 | |
| 178 | class XyWorkbookWriter(_BaseWorkbookWriter): |
| 179 | """ |
| 180 | Determines Excel worksheet layout and can write an Excel workbook from XY |
| 181 | chart data. Serves as the authority for Excel worksheet ranges. |
| 182 | """ |
| 183 | |
| 184 | def series_name_ref(self, series): |
| 185 | """ |
| 186 | Return the Excel worksheet reference to the cell containing the name |
| 187 | for *series*. This also serves as the column heading for the series |
| 188 | Y values. |
| 189 | """ |
| 190 | row = self.series_table_row_offset(series) + 1 |
| 191 | return "Sheet1!$B$%d" % row |
| 192 | |
| 193 | def series_table_row_offset(self, series): |
| 194 | """ |
| 195 | Return the number of rows preceding the data table for *series* in |
| 196 | the Excel worksheet. |
| 197 | """ |
| 198 | title_and_spacer_rows = series.index * 2 |
| 199 | data_point_rows = series.data_point_offset |
| 200 | return title_and_spacer_rows + data_point_rows |
| 201 | |
| 202 | def x_values_ref(self, series): |
| 203 | """ |
| 204 | The Excel worksheet reference to the X values for this chart (not |
| 205 | including the column label). |
| 206 | """ |
| 207 | top_row = self.series_table_row_offset(series) + 2 |
| 208 | bottom_row = top_row + len(series) - 1 |
| 209 | return "Sheet1!$A$%d:$A$%d" % (top_row, bottom_row) |
| 210 | |
| 211 | def y_values_ref(self, series): |
| 212 | """ |
| 213 | The Excel worksheet reference to the Y values for this chart (not |
| 214 | including the column label). |
| 215 | """ |
| 216 | top_row = self.series_table_row_offset(series) + 2 |
| 217 | bottom_row = top_row + len(series) - 1 |
| 218 | return "Sheet1!$B$%d:$B$%d" % (top_row, bottom_row) |
| 219 | |
| 220 | def _populate_worksheet(self, workbook, worksheet): |
| 221 | """ |
| 222 | Write chart data contents to *worksheet* in the standard XY chart |
| 223 | layout. Write the data for each series to a separate two-column |
| 224 | table, X values in column A and Y values in column B. Place the |
| 225 | series label in the first (heading) cell of the column. |
| 226 | """ |
| 227 | chart_num_format = workbook.add_format({"num_format": self._chart_data.number_format}) |
| 228 | for series in self._chart_data: |
| 229 | series_num_format = workbook.add_format({"num_format": series.number_format}) |
| 230 | offset = self.series_table_row_offset(series) |
| 231 | # write X values |
| 232 | worksheet.write_column(offset + 1, 0, series.x_values, chart_num_format) |
| 233 | # write Y values |
| 234 | worksheet.write(offset, 1, series.name) |
| 235 | worksheet.write_column(offset + 1, 1, series.y_values, series_num_format) |
no outgoing calls
searching dependent graphs…