def test_conditional_formatting_addCellIs_notEqual(self): cf = ConditionalFormatting() redFill = Fill() redFill.start_color.index = 'FFEE1111' redFill.end_color.index = 'FFEE1111' redFill.fill_type = Fill.FILL_SOLID cf.addCellIs('U10:U18', 'notEqual', ['U$7'], True, self.workbook, None, None, redFill) cf.addCellIs('V10:V18', '!=', ['V$7'], True, self.workbook, None, None, redFill) rules = cf.cf_rules assert 'U10:U18' in rules assert len(cf.cf_rules['U10:U18']) == 1 assert rules['U10:U18'][0]['priority'] == 1 assert rules['U10:U18'][0]['type'] == 'cellIs' assert rules['U10:U18'][0]['dxfId'] == 0 assert rules['U10:U18'][0]['operator'] == 'notEqual' assert rules['U10:U18'][0]['formula'][0] == 'U$7' assert rules['U10:U18'][0]['stopIfTrue'] == '1' assert 'V10:V18' in rules assert len(cf.cf_rules['V10:V18']) == 1 assert rules['V10:V18'][0]['priority'] == 2 assert rules['V10:V18'][0]['type'] == 'cellIs' assert rules['V10:V18'][0]['dxfId'] == 1 assert rules['V10:V18'][0]['operator'] == 'notEqual' assert rules['V10:V18'][0]['formula'][0] == 'V$7' assert rules['V10:V18'][0]['stopIfTrue'] == '1'
def test_conditional_formatting_add2ColorScale(self): cf = ConditionalFormatting() cf.add2ColorScale('A1:A10', 'min', None, 'FFAA0000', 'max', None, 'FF00AA00') rules = cf.cf_rules assert 'A1:A10' in rules assert len(cf.cf_rules['A1:A10']) == 1 assert rules['A1:A10'][0]['priority'] == 1 assert rules['A1:A10'][0]['type'] == 'colorScale' assert rules['A1:A10'][0]['colorScale']['cfvo'][0]['type'] == 'min' assert rules['A1:A10'][0]['colorScale']['cfvo'][1]['type'] == 'max'
def test_conditional_formatting_add3ColorScale(self): cf = ConditionalFormatting() cf.add3ColorScale('B1:B10', 'percentile', 10, 'FFAA0000', 'percentile', 50, 'FF0000AA', 'percentile', 90, 'FF00AA00') rules = cf.cf_rules assert 'B1:B10' in rules assert len(cf.cf_rules['B1:B10']) == 1 assert rules['B1:B10'][0]['priority'] == 1 assert rules['B1:B10'][0]['type'] == 'colorScale' assert rules['B1:B10'][0]['colorScale']['cfvo'][0]['type'] == 'percentile' assert rules['B1:B10'][0]['colorScale']['cfvo'][0]['val'] == '10' assert rules['B1:B10'][0]['colorScale']['cfvo'][1]['type'] == 'percentile' assert rules['B1:B10'][0]['colorScale']['cfvo'][1]['val'] == '50' assert rules['B1:B10'][0]['colorScale']['cfvo'][2]['type'] == 'percentile' assert rules['B1:B10'][0]['colorScale']['cfvo'][2]['val'] == '90'
def test_conditional_formatting_addCellIs_notBetween(self): cf = ConditionalFormatting() redFill = Fill() redFill.start_color.index = 'FFEE1111' redFill.end_color.index = 'FFEE1111' redFill.fill_type = Fill.FILL_SOLID cf.addCellIs('U10:U18', 'notBetween', ['U$7', 'U$8'], True, self.workbook, None, None, redFill) rules = cf.cf_rules assert 'U10:U18' in rules assert len(cf.cf_rules['U10:U18']) == 1 assert rules['U10:U18'][0]['priority'] == 1 assert rules['U10:U18'][0]['type'] == 'cellIs' assert rules['U10:U18'][0]['dxfId'] == 0 assert rules['U10:U18'][0]['operator'] == 'notBetween' assert rules['U10:U18'][0]['formula'][0] == 'U$7' assert rules['U10:U18'][0]['formula'][1] == 'U$8' assert rules['U10:U18'][0]['stopIfTrue'] == '1'
def test_conditional_formatting_add3ColorScale(self): cf = ConditionalFormatting() cf.add3ColorScale('B1:B10', 'percentile', 10, 'FFAA0000', 'percentile', 50, 'FF0000AA', 'percentile', 90, 'FF00AA00') rules = cf.cf_rules assert 'B1:B10' in rules assert len(cf.cf_rules['B1:B10']) == 1 assert rules['B1:B10'][0]['priority'] == 1 assert rules['B1:B10'][0]['type'] == 'colorScale' assert rules['B1:B10'][0]['colorScale']['cfvo'][0][ 'type'] == 'percentile' assert rules['B1:B10'][0]['colorScale']['cfvo'][0]['val'] == '10' assert rules['B1:B10'][0]['colorScale']['cfvo'][1][ 'type'] == 'percentile' assert rules['B1:B10'][0]['colorScale']['cfvo'][1]['val'] == '50' assert rules['B1:B10'][0]['colorScale']['cfvo'][2][ 'type'] == 'percentile' assert rules['B1:B10'][0]['colorScale']['cfvo'][2]['val'] == '90'
def test_conditional_formatting_addDxfStyle(self): cf = ConditionalFormatting() fill = Fill() fill.start_color.index = 'FFEE1111' fill.end_color.index = 'FFEE1111' fill.fill_type = Fill.FILL_SOLID font = Font() font.name = 'Arial' font.size = 12 font.bold = True font.underline = Font.UNDERLINE_SINGLE borders = Borders() borders.top.border_style = Border.BORDER_THIN borders.top.color.index = Color.DARKYELLOW borders.bottom.border_style = Border.BORDER_THIN borders.bottom.color.index = Color.BLACK dxfId = cf.addDxfStyle(self.workbook, font, borders, fill) assert dxfId == 0 dxfId = cf.addDxfStyle(self.workbook, None, None, fill) assert dxfId == 1 assert len(self.workbook.style_properties['dxf_list']) == 2
def test_conditional_formatting_addCellIs_greaterThanOrEqual(self): cf = ConditionalFormatting() redFill = Fill() redFill.start_color.index = 'FFEE1111' redFill.end_color.index = 'FFEE1111' redFill.fill_type = Fill.FILL_SOLID cf.addCellIs('U10:U18', 'greaterThanOrEqual', ['U$7'], True, self.workbook, None, None, redFill) cf.addCellIs('V10:V18', '>=', ['V$7'], True, self.workbook, None, None, redFill) rules = cf.cf_rules assert 'U10:U18' in rules assert len(cf.cf_rules['U10:U18']) == 1 assert rules['U10:U18'][0]['priority'] == 1 assert rules['U10:U18'][0]['type'] == 'cellIs' assert rules['U10:U18'][0]['dxfId'] == 0 assert rules['U10:U18'][0]['operator'] == 'greaterThanOrEqual' assert rules['U10:U18'][0]['formula'][0] == 'U$7' assert rules['U10:U18'][0]['stopIfTrue'] == '1' assert 'V10:V18' in rules assert len(cf.cf_rules['V10:V18']) == 1 assert rules['V10:V18'][0]['priority'] == 2 assert rules['V10:V18'][0]['type'] == 'cellIs' assert rules['V10:V18'][0]['dxfId'] == 1 assert rules['V10:V18'][0]['operator'] == 'greaterThanOrEqual' assert rules['V10:V18'][0]['formula'][0] == 'V$7' assert rules['V10:V18'][0]['stopIfTrue'] == '1'
def __init__(self, parent_workbook, title='Sheet'): self._parent = parent_workbook self._title = '' if not title: self.title = 'Sheet%d' % (1 + len(self._parent.worksheets)) else: self.title = title self.row_dimensions = {} self.column_dimensions = OrderedDict([]) self.page_breaks = [] self._cells = {} self._styles = {} self._charts = [] self._images = [] self._comment_count = 0 self._merged_cells = [] self.relationships = [] self._data_validations = [] self.selected_cell = 'A1' self.active_cell = 'A1' self.sheet_state = self.SHEETSTATE_VISIBLE self.page_setup = PageSetup() self.page_margins = PageMargins() self.header_footer = HeaderFooter() self.sheet_view = SheetView() self.protection = SheetProtection() self.show_gridlines = True self.print_gridlines = False self.show_summary_below = True self.show_summary_right = True self.default_row_dimension = RowDimension() self.default_column_dimension = ColumnDimension() self._auto_filter = None self._freeze_panes = None self.paper_size = None self.formula_attributes = {} self.orientation = None self.xml_source = None self.conditional_formatting = ConditionalFormatting()
class WS(): conditional_formatting = ConditionalFormatting()