def test_parse_dxfs():
    reference_file = os.path.join(DATADIR, 'reader', 'conditional-formatting.xlsx')
    wb = load_workbook(reference_file)
    archive = ZipFile(reference_file, 'r', ZIP_DEFLATED)
    read_xml = archive.read(ARC_STYLE)

    # Verify length
    assert '<dxfs count="164">' in str(read_xml)
    assert len(wb.style_properties['dxf_list']) == 164

    # Verify first dxf style
    reference_file = os.path.join(DATADIR, 'writer', 'expected', 'dxf_style.xml')
    with open(reference_file) as expected:
        diff = compare_xml(read_xml, expected.read())
        assert diff is None, diff

    cond_styles = wb.style_properties['dxf_list'][0]
    assert cond_styles['font']['color'] == Color('FF9C0006')
    assert cond_styles['font']['bold'] == False
    assert cond_styles['font']['italic'] == False
    f = Fill()
    f.end_color = Color('FFFFC7CE')
    assert cond_styles['fill'][0] == f

    # Verify that the dxf styles stay the same when they're written and read back in.
    w = StyleWriter(wb)
    w._write_dxfs()
    write_xml = get_xml(w._root)
    read_style_prop = read_style_table(write_xml)
    assert len(read_style_prop['dxf_list']) == len(wb.style_properties['dxf_list'])
    for i, dxf in enumerate(read_style_prop['dxf_list']):
        assert repr(wb.style_properties['dxf_list'][i] == dxf)
Exemplo n.º 2
0
 def test_fonts(self):
     self.worksheet.cell('A1').style.font.size = 12
     self.worksheet.cell('A1').style.font.bold = True
     w = StyleWriter(self.workbook)
     w._write_fonts()
     expected = """<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="2"><font><sz val="11" /><color theme="1" /><name val="Calibri" /><family val="2" /><scheme val="minor" /></font><font><sz val="12" /><color rgb="FF000000" /><name val="Calibri" /><family val="2" /><b /></font></fonts></styleSheet>"""
     xml = get_xml(w._root)
     diff = compare_xml(xml, expected)
     assert diff is None, diff
Exemplo n.º 3
0
 def test_alignment(self):
     self.worksheet.cell('A1').style.alignment.horizontal = 'center'
     self.worksheet.cell('A1').style.alignment.vertical = 'center'
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     assert 'applyAlignment="1"' in xml
     assert 'horizontal="center"' in xml
     assert 'vertical="center"' in xml
Exemplo n.º 4
0
 def test_fills(self):
     self.worksheet.cell('A1').style.fill.fill_type = 'solid'
     self.worksheet.cell(
         'A1').style.fill.start_color.index = Color.DARKYELLOW
     w = StyleWriter(self.workbook)
     w._write_fills()
     expected = """<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fills count="3"><fill><patternFill patternType="none" /></fill><fill><patternFill patternType="gray125" /></fill><fill><patternFill patternType="solid"><fgColor rgb="FF808000" /></patternFill></fill></fills></styleSheet>"""
     xml = get_xml(w._root)
     diff = compare_xml(xml, expected)
     assert diff is None, diff
Exemplo n.º 5
0
 def test_write_cell_xfs_1(self):
     self.worksheet.cell('A1').style.font.size = 12
     w = StyleWriter(self.workbook)
     ft = w._write_fonts()
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, ft, {}, {})
     xml = get_xml(w._root)
     assert 'applyFont="1"' in xml
     assert 'applyFill="1"' not in xml
     assert 'applyBorder="1"' not in xml
     assert 'applyAlignment="1"' not in xml
Exemplo n.º 6
0
 def test_borders(self):
     self.worksheet.cell(
         'A1').style.borders.top.border_style = Border.BORDER_THIN
     self.worksheet.cell(
         'A1').style.borders.top.color.index = Color.DARKYELLOW
     w = StyleWriter(self.workbook)
     w._write_borders()
     expected = """<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><borders count="2"><border><left /><right /><top /><bottom /><diagonal /></border><border><left /><right /><top style="thin"><color rgb="FF808000" /></top><bottom /><diagonal /></border></borders></styleSheet>"""
     xml = get_xml(w._root)
     diff = compare_xml(xml, expected)
     assert diff is None, diff
Exemplo n.º 7
0
 def test_alignment_rotation(self):
     self.worksheet.cell('A1').style.alignment.vertical = 'center'
     self.worksheet.cell('A1').style.alignment.text_rotation = 90
     self.worksheet.cell('A2').style.alignment.vertical = 'center'
     self.worksheet.cell('A2').style.alignment.text_rotation = 135
     self.worksheet.cell('A3').style.alignment.text_rotation = -34
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     assert 'textRotation="90"' in xml
     assert 'textRotation="135"' in xml
     assert 'textRotation="124"' in xml
Exemplo n.º 8
0
 def test_alignment_indent(self):
     self.worksheet.cell('A1').style.alignment.indent = 1
     self.worksheet.cell('A2').style.alignment.indent = 4
     self.worksheet.cell('A3').style.alignment.indent = 0
     self.worksheet.cell('A3').style.alignment.indent = -1
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     assert 'indent="1"' in xml
     assert 'indent="4"' in xml
     #Indents not greater than zero are ignored when writing
     assert 'indent="0"' not in xml
     assert 'indent="-1"' not in xml