def owriteRow(self, row): # COLSPAN FIXME tr = table.TableRow() for c in row.children: cs = c.colspan self.write(c,tr) if cs: tr.lastChild.setAttribute("numbercolumnsspanned",str(cs)) for i in range(cs): tr.addElement(table.CoveredTableCell()) return SkipChildren(tr)
def __call__(self): datatable = table.Table(name="local-table") if self.datasourcehaslabels in ('row', 'both'): t = table.TableHeaderColumns() t.addElement(table.TableColumn()) datatable.addElement(t) t = table.TableColumns() if self.datasourcehaslabels in ('row', 'both'): t.addElement( table.TableColumn(numbercolumnsrepeated=str(self.numcols - 1))) else: t.addElement( table.TableColumn(numbercolumnsrepeated=str(self.numcols))) datatable.addElement(t) if self.datasourcehaslabels in ('column', 'both'): t = table.TableHeaderRows() datatable.addElement(t) tr = table.TableRow() t.addElement(tr) content = self.values[0] for val in content: tc = table.TableCell(valuetype=valuetype(val)) tr.addElement(tc) tc.addElement(text.P(text=str(val))) t = table.TableRows() datatable.addElement(t) rownum = 0 for content in self.values: if rownum == 0 and self.datasourcehaslabels in ('column', 'both'): rownum += 1 continue tr = table.TableRow() t.addElement(tr) for val in content: tc = table.TableCell(valuetype=valuetype(val), value=val) tr.addElement(tc) tc.addElement(text.P(text=str(val))) rownum += 1 return datatable
def _render_name_freq(self, freq_table): """Produces name statistics table. :param freq_table: list of (name, count) tuples. """ def _gencouples(namefreq): halflen = (len(namefreq) + 1) // 2 for i in range(halflen): n1, c1 = namefreq[2 * i] n2, c2 = None, None if 2 * i + 1 < len(namefreq): n2, c2 = namefreq[2 * i + 1] yield n1, c1, n2, c2 total = float(sum(count for _, count in freq_table)) tbl = table.Table() tbl.addElement(table.TableColumn()) tbl.addElement(table.TableColumn()) tbl.addElement(table.TableColumn()) tbl.addElement(table.TableColumn()) for name1, count1, name2, count2 in _gencouples(freq_table): row = table.TableRow() cell = table.TableCell() cell.addElement(text.P(text=name1 or '-')) row.addElement(cell) cell = table.TableCell() cell.addElement( text.P(text='%d (%.1f%%)' % (count1, count1 / total * 100))) row.addElement(cell) if count2 is not None: cell = table.TableCell() cell.addElement(text.P(text=name2 or '-')) row.addElement(cell) cell = table.TableCell() cell.addElement( text.P(text='%d (%.1f%%)' % (count2, count2 / total * 100))) row.addElement(cell) tbl.addElement(row) self.doc.text.addElement(tbl)
def __init__(self, sheet: AQOdsSheet) -> None: """ Initialize a line inside a sheet. @param sheet. Parent Document Sheet. """ self.sheet_ = sheet self.row_ = table.TableRow() self.cells_list_ = [] self.fix_precision_ = None self.row_color_ = None self.property_cell_ = [] self.style_cell_text_ = None
def dset_sheet(cls, dataset, ws): """Completes given worksheet from given Dataset.""" _package = dataset._package(dicts=False) for i, sep in enumerate(dataset._separators): _offset = i _package.insert((sep[0] + _offset), (sep[1], )) for i, row in enumerate(_package): row_number = i + 1 odf_row = table.TableRow(stylename=bold, defaultcellstylename='bold') for j, col in enumerate(row): try: col = str(col, errors='ignore') except TypeError: # col is already str pass ws.addElement(table.TableColumn()) # bold headers if (row_number == 1) and dataset.headers: odf_row.setAttribute('stylename', bold) ws.addElement(odf_row) cell = table.TableCell() p = text.P() p.addElement(text.Span(text=col, stylename=bold)) cell.addElement(p) odf_row.addElement(cell) # wrap the rest else: try: if '\n' in col: ws.addElement(odf_row) cell = table.TableCell() cell.addElement(text.P(text=col)) odf_row.addElement(cell) else: ws.addElement(odf_row) cell = table.TableCell() cell.addElement(text.P(text=col)) odf_row.addElement(cell) except TypeError: ws.addElement(odf_row) cell = table.TableCell() cell.addElement(text.P(text=col)) odf_row.addElement(cell)
def _render_name_freq(self, freq_table): # docstring inherited from base class def _gencouples(namefreq): halflen = (len(namefreq) + 1) // 2 for i in range(halflen): n1, c1 = namefreq[2 * i] n2, c2 = None, None if 2 * i + 1 < len(namefreq): n2, c2 = namefreq[2 * i + 1] yield n1, c1, n2, c2 total = float(sum(count for _, count in freq_table)) tbl = table.Table() tbl.addElement(table.TableColumn()) tbl.addElement(table.TableColumn()) tbl.addElement(table.TableColumn()) tbl.addElement(table.TableColumn()) for name1, count1, name2, count2 in _gencouples(freq_table): row = table.TableRow() cell = table.TableCell() cell.addElement(text.P(text=name1 or '-')) row.addElement(cell) cell = table.TableCell() cell.addElement( text.P(text='%d (%.1f%%)' % (count1, count1 / total * 100))) row.addElement(cell) if count2 is not None: cell = table.TableCell() cell.addElement(text.P(text=name2 or '-')) row.addElement(cell) cell = table.TableCell() cell.addElement( text.P(text='%d (%.1f%%)' % (count2, count2 / total * 100))) row.addElement(cell) tbl.addElement(row) self.doc.text.addElement(tbl)
def _write_journal(self, journal): path = os.path.join( options.REPORTS_DIR, 'Журнал {} {} {}.odt'.format( self.year, self.months[self.month], self.doctor[1], )) doc = opendocument.OpenDocumentText() table_style = style.Style(name='tableStyle', family='table', masterpagename='masterQ') page_layout = style.PageLayout(name='pageStyle') page_layout.addElement( style.PageLayoutProperties( printorientation='landscape', margin='0cm', pagewidth='290cm', pageheight='21cm', )) master_q = style.MasterPage(name='masterQ', pagelayoutname=page_layout) doc.automaticstyles.addElement(table_style) doc.automaticstyles.addElement(page_layout) doc.masterstyles.addElement(master_q) journal = ([['Дата', 'ФИО', 'Дата Рождения', 'Адрес', 'Заключение']] + journal) _table = table.Table(name='journal') _table.addElement( table.TableColumn(numbercolumnsrepeated=len(journal[0]))) for data in journal: row = table.TableRow() _table.addElement(row) for col in data: cell = table.TableCell(valuetype='string') cell.addElement(text.P(text=str(col or ''))) row.addElement(cell) doc.text.addElement(_table) try: doc.save(path) except PermissionError: self.main_window.create_alert( 'Файл журнала используется.\nЗакройте его и создайте снова.') return self._open(path)
def create_stats(solvers, s, min=2, max=2): if s == 'count': runtimes = '' counts = '=COUNT(INDIRECT(ADDRESS({0}; CELL("COL")-1) & ":" & ADDRESS({1}; CELL("COL")-1)))' else: runtimes = '=SUMIF(INDIRECT(ADDRESS({0}; CELL("COL")+1) & ":" & ADDRESS({1}; CELL("COL")+1)); "{2}"; INDIRECT(ADDRESS({0}; CELL("COL")) & ":" & ADDRESS({1}; CELL("COL"))))' counts = '=COUNTIF(INDIRECT(ADDRESS({0}; CELL("COL")) & ":" & ADDRESS({1}; CELL("COL"))); "{2}")' tr = table.TableRow() tr.addElement(create_cell_string(s)) for _ in solvers: if runtimes == '': tr.addElement(create_cell_string()) else: tr.addElement(create_cell_formula(runtimes.format(min, max, s))) tr.addElement(create_cell_formula(counts.format(min, max, s))) return tr
def __add_row_to_table(table): table_row = odf_table.TableRow() table.addElement(table_row) return table_row
body_info = chandler.getBody() #return a dictionary uf = UserFieldDecls() textdoc.text.addElement(uf) # Add user fields for id,transunit in body_info.items(): uf.addElement(UserFieldDecl(name=id,valuetype="string", stringvalue=transunit['target'])) # Start the table, and describe the columns mytable = table.Table(protected="true") mytable.addElement(table.TableColumn(numbercolumnsrepeated=2,stylename=widthwide)) for id,transunit in body_info.items(): tr = table.TableRow() mytable.addElement(tr) tc = table.TableCell(stylename=tcstyle, qattributes={(TABLENS,'protected'):'true'}) tr.addElement(tc) p = P(stylename=tablecontents,text=transunit['source']) tc.addElement(p) tc = table.TableCell(qattributes={(TABLENS,'protected'):'true'}) tr.addElement(tc) p = P(stylename=tablecontents) tc.addElement(p) f = UserFieldInput(name=id,description="Enter translation") p.addElement(f) textdoc.text.addElement(mytable)
def s_html_tr(self, tag, attrs): e = table.TableRow() self.curr.addElement(e) self.curr = e
def create_row(cells): tr = table.TableRow() for c in cells: tr.addElement(c) return tr