MCPcopy Create free account
hub / github.com/scanny/python-pptx / XyWorkbookWriter

Class XyWorkbookWriter

src/pptx/chart/xlsx.py:178–235  ·  view source on GitHub ↗

Determines Excel worksheet layout and can write an Excel workbook from XY chart data. Serves as the authority for Excel worksheet ranges.

Source from the content-addressed store, hash-verified

176
177
178class 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)

Callers 2

_workbook_writerMethod · 0.90
populate_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 1

populate_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…