def it_provides_access_to_its_cells(self, tbl_, tc_, _Cell_, cell_): row_idx, col_idx = 4, 2 tbl_.tc.return_value = tc_ _Cell_.return_value = cell_ table = Table(tbl_, None) cell = table.cell(row_idx, col_idx) tbl_.tc.assert_called_once_with(row_idx, col_idx) _Cell_.assert_called_once_with(tc_, table) assert cell is cell_
def it_provides_access_to_its_cells(self, tbl_, tc_, _Cell_, cell_): row_idx, col_idx = 4, 2 tbl_.tc.return_value = tc_ _Cell_.return_value = cell_ table = Table(tbl_, None) cell = table.cell(row_idx, col_idx) tbl_.tc.assert_called_once_with(row_idx, col_idx) _Cell_.assert_called_once_with(tc_, table) assert cell is cell_
def it_can_iterate_its_grid_cells(self, request, _Cell_): tbl = element("a:tbl/(a:tr/(a:tc,a:tc),a:tr/(a:tc,a:tc))") expected_tcs = tbl.xpath(".//a:tc") expected_cells = _Cell_.side_effect = [ instance_mock(request, _Cell, name="cell%d" % idx) for idx in range(4) ] table = Table(tbl, None) cells = list(table.iter_cells()) assert cells == expected_cells assert _Cell_.call_args_list == [call(tc, table) for tc in expected_tcs]
def write_table(self, table: Table) -> None: """Write attributes to table object.""" if self.first_row_header is not None: table._tbl.firstRow = self.first_row_header if self.col_banding is not None: table.vert_banding = self.col_banding if self.row_banding is not None: table.horz_banding = self.row_banding if self.width is not None: self._write_col_sizes(table) self._write_all_cells(table)
def it_can_iterate_its_grid_cells(self, request, _Cell_): tbl = element('a:tbl/(a:tr/(a:tc,a:tc),a:tr/(a:tc,a:tc))') expected_tcs = tbl.xpath('.//a:tc') expected_cells = _Cell_.side_effect = [ instance_mock(request, _Cell, name='cell%d' % idx) for idx in range(4) ] table = Table(tbl, None) cells = list(table.iter_cells()) assert cells == expected_cells assert _Cell_.call_args_list == [ call(tc, table) for tc in expected_tcs ]
def _populate_table(table: Table, cols: List[str], rows: List[str], values: List[List[str]], first_cell: str = ' ') -> Table: """populate the cells of a pptx table from lists""" table.cell(0, 0).text = str(first_cell) for j, col in enumerate(cols): table.cell(0, j + 1).text = str(col) for i, row in enumerate(rows): table.cell(i + 1, 0).text = str(row) for j in range(len(cols)): for i in range(len(rows)): table.cell(i + 1, j + 1).text = str(values[i][j]) return table
def table(self): """ The |Table| object contained in this graphic frame. Raises |ValueError| if this graphic frame does not contain a table. """ if not self.has_table: raise ValueError('shape does not contain a table') tbl = self._element.graphic.graphicData.tbl return Table(tbl, self)
def generate_content(self, pptx_table: Table): for col_nr, pptx_col in enumerate(pptx_table.columns): pptx_col.width = self._column_widths[col_nr] for row_index, row in enumerate(self._rows): pptx_row: _Row = pptx_table.rows[row_index] pptx_row.height = row.height for col_index, row_cell in enumerate(row._row_cells): cell = pptx_table.cell(row_index, col_index) row_cell.apply_styles(cell)
def it_provides_access_to_its_rows(self, request): rows_ = instance_mock(request, _RowCollection) _RowCollection_ = class_mock(request, "pptx.table._RowCollection", return_value=rows_) tbl = element("a:tbl") table = Table(tbl, None) rows = table.rows _RowCollection_.assert_called_once_with(tbl, table) assert rows is rows_
def it_provides_access_to_its_columns(self, request): columns_ = instance_mock(request, _ColumnCollection) _ColumnCollection_ = class_mock(request, "pptx.table._ColumnCollection", return_value=columns_) tbl = element("a:tbl") table = Table(tbl, None) columns = table.columns _ColumnCollection_.assert_called_once_with(tbl, table) assert columns is columns_
def dy_fixture(self, graphic_frame_): tbl_cxml = 'a:tbl/(a:tr{h=100},a:tr{h=200})' table = Table(element(tbl_cxml), graphic_frame_) expected_height = 300 return table, expected_height
def dx_fixture(self, graphic_frame_): tbl_cxml = 'a:tbl/a:tblGrid/(a:gridCol{w=111},a:gridCol{w=222})' table = Table(element(tbl_cxml), graphic_frame_) expected_width = 333 return table, expected_width
def boolprop_set_fixture(self, request): tbl_cxml, boolprop_name, new_value, expected_tbl_cxml = request.param table = Table(element(tbl_cxml), None) expected_xml = xml(expected_tbl_cxml) return table, boolprop_name, new_value, expected_xml
def boolprop_get_fixture(self, request): tbl_cxml, boolprop_name, expected_value = request.param table = Table(element(tbl_cxml), None) return table, boolprop_name, expected_value
def table(self): return Table(element('a:tbl'), None)
def table(self): return Table(element("a:tbl"), None)