Пример #1
0
    def get_donor_cell(self):
        size = 9

        if self.has_acceptor:
            cell = WriteOnlyCell(ws_result, value='OK')
            cell.fill = PatternFill(start_color='FFdff0d8',
                                    end_color='FFdff0d8',
                                    fill_type='solid')
            cell.font = Font(name=self.font,
                             size=size,
                             color='3c763d',
                             bold=True)
            cell.comment = Comment(text="Good =)", author=self.author)
        else:
            cell = WriteOnlyCell(ws_result, value='NO')
            cell.fill = PatternFill(start_color='FFf2dede',
                                    end_color='FFf2dede',
                                    fill_type='solid')
            cell.font = Font(name=self.font,
                             size=size,
                             color='a94442',
                             bold=True)
            cell.comment = Comment(
                text="There are no acceptor ({}) on the site: {}".format(
                    self.acceptor, self.donor),
                author=self.author)

        return cell
Пример #2
0
def f_cs_que(data):
    wb = openpyxl.Workbook(write_only=True)
    ws = wb.create_sheet('Out')
    all_ngss = {}
    for kt, t in data.items():
        ngss = None
        row = [int(kt)]
        elem = elem_que(t)
        for w in t.words:
            if w in elem:
                cpt = elem.index(w)
                c = WriteOnlyCell(ws, value=w.form)
                c.fill = patterns[cpt]
                if cpt == 0:
                    ngss = w.lemma
                    if w.lemma not in all_ngss:
                        all_ngss[w.lemma] = 1
                    else:
                        all_ngss[w.lemma] += 1
                row.append(c)
            else:
                row.append(w.form)
        ws.append(row)
    ws = wb.create_sheet('NGSS')
    ngss_total = sum(all_ngss.values())
    for k in sorted(all_ngss, key=all_ngss.get, reverse=True):
        ws.append([k, all_ngss[k], all_ngss[k] / ngss_total])
    ws = wb.create_sheet('Info')
    ws.append(['Total occ NGSS', ngss_total])
    ws.append(['Total res', len(data)])
    wb.save('CS-que.xlsx')
Пример #3
0
    def __get_cell(self, string, color=None, style=None):
        """
        Helper method for log message. This method takes a string as well as color and style
        arguments to create a write-only cell.

        Args:
            string: a string object to be written to the cell's value field.
            color: a string object containing a color hex code "######"
            style: a string choosing 1 of 3 formatting options (ITALICS, BOLD, UNDERLINED)
        """
        if not MODULE_INSTALLED:
            return

        cell = WriteOnlyCell(self.worksheet, value=string)
        if color is not None:
            # pylint: disable=E0237
            cell.fill = PatternFill("solid", fgColor=color)
        # pylint: disable=E0237
        cell.font = Font(
            name=self.font_name,
            bold=(style == self.BOLD),
            italic=(style == self.ITALICS),
            underline=("single" if style == self.UNDERLINED else "none"),
        )
        # pylint: disable=E0237
        cell.alignment = self.__align
        return cell
Пример #4
0
def f_cs_n_est_n(data):
    wb = openpyxl.Workbook(write_only=True)
    ws = wb.create_sheet('Out')
    all_ngss = {}
    all_nco = {}
    all_cs = {}
    for kt, t in data.items():
        ngss = None
        row = [int(kt)]
        elem = elem_n_est_n(t)
        for w in t.words:
            if w in elem:
                cpt = elem.index(w)
                c = WriteOnlyCell(ws, value=w.form)
                c.fill = patterns[cpt]
                if cpt == 0:
                    ngss = w.lemma
                    if w.lemma not in all_ngss:
                        all_ngss[w.lemma] = 1
                    else:
                        all_ngss[w.lemma] += 1
                elif cpt == 1:
                    pass
                elif cpt == 2:
                    nco = w.lemma
                    if w.lemma not in all_nco:
                        all_nco[w.lemma] = 1
                    else:
                        all_nco[w.lemma] += 1 
                    cs = (ngss, nco)
                    if cs not in all_cs:
                        all_cs[cs] = 1
                    else:
                        all_cs[cs] += 1
                row.append(c)
            else:
                row.append(w.form)
        ws.append(row)
    ws = wb.create_sheet('NGSS')
    ngss_total = sum(all_ngss.values())
    for k in sorted(all_ngss, key=all_ngss.get, reverse=True):
        ws.append([k, all_ngss[k], all_ngss[k] / ngss_total])
    ws = wb.create_sheet('NCO')
    nco_total = sum(all_nco.values())
    for k in sorted(all_nco, key=all_nco.get, reverse=True):
        ws.append([k, all_nco[k], all_nco[k] / nco_total])
    ws = wb.create_sheet('CS')
    cs_total = sum(all_cs.values())
    for k in sorted(all_cs, key=all_cs.get, reverse=True):
        ws.append([*k, all_cs[k], all_cs[k] / cs_total])
    ws = wb.create_sheet('Info')
    ws.append(['Total occ NGSS', ngss_total])
    ws.append(['Total occ NCO', nco_total])
    ws.append(['Total diff CS', cs_total])
    ws.append(['Total res', len(data)])
    wb.save('CS-n_est_n.xlsx')
Пример #5
0
    def save(self):
        from openpyxl import Workbook
        from openpyxl.cell import WriteOnlyCell
        from openpyxl.styles import PatternFill, Alignment

        self.check_is_ready()

        self.wb = Workbook(write_only=True)

        meta_ws = self.wb.create_sheet()
        meta_ws.title = "meta"
        meta_ws.sheet_properties.tabColor = "8888ff"

        meta_ws.column_dimensions['A'].width = 15
        meta_ws.column_dimensions['B'].width = 40
        meta_ws.column_dimensions['C'].width = 20
        meta_ws.column_dimensions['D'].width = 20
        meta_ws.column_dimensions['E'].width = 20

        self.sections.resources.sort_by_term()

        self.load_declares()

        self.doc.cleanse()

        self._load_resources()

        self._clean_doc()

        fill = PatternFill(
            "solid", fgColor="acc0e0")  # PatternFill(patternType='gray125')
        table_fill = PatternFill(
            "solid", fgColor="d9dce0")  # PatternFill(patternType='gray125')

        alignment = Alignment(wrap_text=False)

        self._doc['Root'].get_or_new_term('Root.Issued').value = datetime_now()

        for i, row in enumerate(self.doc.rows, 1):

            if row[0] == 'Section' or row[0] == 'Table':
                styled_row = []
                for c in row + [''] * 5:
                    cell = WriteOnlyCell(meta_ws, value=c)
                    cell.fill = fill if row[0] == 'Section' else table_fill
                    styled_row.append(cell)
                meta_ws.append(styled_row)

            else:
                meta_ws.append(row)

        self.wb.save(self.package_path.path)

        return self.package_path
Пример #6
0
def f_cs_de_inf(data):
    wb = openpyxl.Workbook(write_only=True)
    ws = wb.create_sheet('Out')
    all_ngss = {}
    all_inf = {}
    all_cs = {}
    for kt, t in data.items():
        ngss = None
        row = [int(kt)]
        elem = elem_cs_de_inf(t)
        for w in t.words:
            if w in elem:
                cpt = elem.index(w)
                c = WriteOnlyCell(ws, value=w.form)
                c.fill = patterns[cpt]
                if cpt == 0:
                    ngss = w.lemma
                    if w.lemma not in all_ngss:
                        all_ngss[w.lemma] = 1
                    else:
                        all_ngss[w.lemma] += 1
                elif cpt == 2: # on ne retient pas le "être" optionnel
                    cs = (ngss, 'de', w.lemma)
                    if w.lemma not in all_inf:
                        all_inf[w.lemma] = 1
                    else:
                        all_inf[w.lemma] += 1
                    if cs not in all_cs:
                        all_cs[cs] = 1
                    else:
                        all_cs[cs] += 1
                row.append(c)
            else:
                row.append(w.form)
        ws.append(row)
    ws = wb.create_sheet('NGSS')
    ngss_total = sum(all_ngss.values())
    for k in sorted(all_ngss, key=all_ngss.get, reverse=True):
        ws.append([k, all_ngss[k], all_ngss[k] / ngss_total])
    ws = wb.create_sheet('INF')
    inf_total = sum(all_inf.values())
    for k in sorted(all_inf, key=all_inf.get, reverse=True):
        ws.append([k, all_inf[k], all_inf[k] / inf_total])
    ws = wb.create_sheet('CS')
    cs_total = sum(all_cs.values())
    for k in sorted(all_cs, key=all_cs.get, reverse=True):
        ws.append([*k, all_cs[k], all_cs[k] / cs_total])
    ws = wb.create_sheet('Info')
    ws.append(['Total occ NGSS', ngss_total])
    ws.append(['Total occ CS', cs_total])
    ws.append(['Total res', len(data)])
    wb.save('CS-inf.xlsx')
Пример #7
0
 def make_sheet(self, title: str, headers: List[str]) -> Worksheet:
     sheet = self.workbook.create_sheet(title=title)
     sheet.freeze_panes = "A2"
     sheet.sheet_properties.filterMode = True
     cells = []
     for header in headers:
         header_ = sanitize_text(header)
         cell = WriteOnlyCell(sheet, value=header_)
         cell.font = self.HEADER_FONT
         cell.fill = self.HEADER_FILL
         cells.append(cell)
     sheet.append(cells)
     return sheet
Пример #8
0
    def write_to_new_file(self, path):
        write_work_book = xl.Workbook(write_only=True)
        ws = write_work_book.create_sheet('Sample list')
        read_work_sheet = self.workbook['Sample list']
        normal_style = self.workbook._named_styles['Normal']
        for row in read_work_sheet.iter_rows():
            write_row = list()
            for cell in row:
                write_cell = WriteOnlyCell(ws, value=cell.value)
                if cell.font != normal_style.font:
                    write_cell.font = cell.font
                if cell.fill is not None:
                    write_cell.fill = cell.fill
                write_row.append(write_cell)
            ws.append(write_row)

        write_work_book.save(path)