def test_is_not_date_color_format():

    wb = Workbook()
    ws = Worksheet(wb)
    cell = Cell(ws, 'A', 1)

    cell.value = -13.5
    cell.style = cell.style.copy(number_format='0.00_);[Red]\(0.00\)')

    assert cell.is_date() is False
def test_is_not_date_color_format():

    wb = Workbook()
    ws = Worksheet(wb)
    cell = Cell(ws, 'A', 1)

    cell.value = -13.5
    cell.style = cell.style.copy(number_format='0.00_);[Red]\(0.00\)')

    assert cell.is_date() is False
Example #3
0
def setStyle(ws, value, style):
    # Silence the warning about using a composite Style object instead of Font.
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", UserWarning)
        try:
            result = [Cell(ws, column='A', row = 1, value=item) for item in value]
            for cell in result:
                cell.style = style
        except TypeError:
            result = Cell(ws, column='A', row = 1, value=value)
            result.style = style
    return result
Example #4
0
def print_sales_content(collection, ws):
    # Table Header
    table_headers = ['Date', 'O.R. #', 'Name', 'Amount', 'Remarks']
    table_header_cells = []

    for h in table_headers:
        c = underline_border_cell(h, ws)
        table_header_cells.append(c)
    r = [''] + table_header_cells
    ws.append(r)

    sales_total = 0
    for item in collection:
        if item.label == 'Cemetery Lot':
            amount = item.lot_area * item.price_per_sq_mtr
        # elif item.label == 'Cremation': # todo no amount for cremation yet
        #     amount = 0
        elif item.label == 'Columbary':
            amount = item.price if item.price is not None else 0

        amount_formatted = 'P {:20,.2f}'.format(amount)
        amount_formatted_cell = Cell(ws, value=amount_formatted)
        amount_formatted_cell.style = Style(alignment=Alignment(
            horizontal='right'))
        client_name = item.client.get_full_name(
        ) if item.client is not None else ''

        sales_total += amount
        ws.append([
            '', item.date_purchased, item.or_no, client_name,
            amount_formatted_cell, item.label
        ])

    # Sales Total
    total_label_cell = Cell(ws, value='TOTAL')
    total_label_cell.font = Font(size=12, color='FFFF0000')

    total_cell = Cell(ws, value='P {:20,.2f}'.format(sales_total))
    total_cell.font = Font(size=12, color='FFFF0000')
    total_cell.border = total_border
    total_cell.alignment = Alignment(horizontal='right')

    ws.append(['', '', '', total_label_cell, total_cell])
def print_sales_content(collection, ws):
    # Table Header
    table_headers = ['Date', 'O.R. #', 'Name', 'Amount', 'Remarks']
    table_header_cells = []

    for h in table_headers:
        c = underline_border_cell(h, ws)
        table_header_cells.append(c)
    r = [''] + table_header_cells
    ws.append(r)

    sales_total = 0
    for item in collection:
        if item.label == 'Cemetery Lot':
            amount = item.lot_area * item.price_per_sq_mtr
        # elif item.label == 'Cremation': # todo no amount for cremation yet
        #     amount = 0
        elif item.label == 'Columbary':
            amount = item.price if item.price is not None else 0

        amount_formatted = 'P {:20,.2f}'.format(amount)
        amount_formatted_cell = Cell(ws, value=amount_formatted)
        amount_formatted_cell.style = Style(alignment=Alignment(horizontal='right'))
        client_name = item.client.get_full_name() if item.client is not None else ''

        sales_total += amount
        ws.append(['', item.date_purchased, item.or_no, client_name, amount_formatted_cell, item.label])

    # Sales Total
    total_label_cell = Cell(ws, value='TOTAL')
    total_label_cell.font = Font(size=12, color='FFFF0000')

    total_cell = Cell(ws, value='P {:20,.2f}'.format(sales_total))
    total_cell.font = Font(size=12, color='FFFF0000')
    total_cell.border = total_border
    total_cell.alignment = Alignment(horizontal='right')

    ws.append(['', '', '', total_label_cell, total_cell])
Example #6
0
    def set_col_widths(self):
        from openpyxl.utils.cell import get_column_letter
        from openpyxl.cell import Cell
        TYPE_STRING = Cell.TYPE_STRING

        for idx, width in sorted(self._col_widths.iteritems()):
            letter = get_column_letter(idx + 1)
            self.sheet.column_dimensions[letter].width = 1 + min(width, 50)
        for row in self._rows:
            values = []
            for val in row:
                if val:
                    value = val.value
                    cell = Cell(self.sheet, column='A', row=1)
                    if isinstance(value, basestring):
                        cell.set_explicit_value(value, data_type=TYPE_STRING)
                    else:
                        cell.value = value
                    cell.style = val.style
                else:
                    cell = val
                values.append(cell)
            self.sheet.append(values)
        self._rows[:] = ()
Example #7
0
    def set_col_widths(self):
        from openpyxl.utils.cell import get_column_letter
        from openpyxl.cell import Cell
        TYPE_STRING = Cell.TYPE_STRING

        for idx, width in sorted(self._col_widths.iteritems()):
            letter = get_column_letter(idx + 1)
            self.sheet.column_dimensions[letter].width = 1 + min(width, 50)
        for row in self._rows:
            values = []
            for val in row:
                if val:
                    value = val.value
                    cell = Cell(self.sheet, column='A', row=1)
                    if isinstance(value, basestring):
                        cell.set_explicit_value(value, data_type=TYPE_STRING)
                    else:
                        cell.value = value
                    cell.style = val.style
                else:
                    cell = val
                values.append(cell)
            self.sheet.append(values)
        self._rows[:] = ()