Exemplo n.º 1
0
    def test_xfs_fonts(self):
        st = Style(font=Font(size=12, bold=True))
        self.worksheet.cell('A1').style = st
        w = StyleWriter(self.workbook)

        nft = borders = fills = DummyElement()
        fonts = Element("fonts")
        w._write_cell_xfs(nft, fonts, fills, borders)
        xml = get_xml(w._root)
        assert """applyFont="1" """ in xml
        assert """fontId="1" """ in xml

        expected = """
        <fonts count="2">
        <font>
            <sz val="12.0" />
            <color rgb="00000000"></color>
            <name val="Calibri" />
            <family val="2" />
            <b></b>
        </font>
        </fonts>
        """
        xml = get_xml(fonts)
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_protection(self):
        prot = Protection(locked=True,
                          hidden=True)
        self.worksheet.cell('A1').style = Style(protection=prot)
        w = StyleWriter(self.workbook)
        w._write_protection(w._root, prot)
        xml = tostring(w._root)
        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
          <protection hidden="1" locked="1"/>
        </styleSheet>
                """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        nft = fonts = borders = fills = Element('empty')
        w._write_cell_xfs(nft, fonts, fills, borders)
        xml = tostring(w._root)
        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
          <protection hidden="1" locked="1"/>
          <cellXfs count="2">
            <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
            <xf applyProtection="1" borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0">
              <protection hidden="1" locked="1"/>
            </xf>
          </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_xfs_number_format(self):
        for o in range(1, 4):
            for i in range(1, 4):
                # Two of these are custom, 0.0% and 0.000%. 0.00% is a built in format ID
                self.worksheet.cell(row=o, column=i).number_format = '0.' + '0' * i + '%'
        w = StyleWriter(self.workbook)
        fonts = borders = fills = DummyElement()
        nft = SubElement(w._root, 'numFmts')
        w._write_cell_xfs(nft, fonts, fills, borders)

        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
            <numFmts count="2">
                <numFmt formatCode="0.0%" numFmtId="165"/>
                <numFmt formatCode="0.000%" numFmtId="166"/>
            </numFmts>
            <cellXfs count="4">
                <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
                <xf applyNumberFormat="1" borderId="0" fillId="0" fontId="0" numFmtId="165" xfId="0"/>
                <xf applyNumberFormat="1" borderId="0" fillId="0" fontId="0" numFmtId="10" xfId="0"/>
                <xf applyNumberFormat="1" borderId="0" fillId="0" fontId="0" numFmtId="166" xfId="0"/>
            </cellXfs>
        </styleSheet>
        """

        xml = tostring(w._root)
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Exemplo n.º 4
0
    def test_protection(self):
        prot = Protection(locked=True, hidden=True)
        self.worksheet.cell('A1').style = Style(protection=prot)
        w = StyleWriter(self.workbook)
        w._write_protection(w._root, prot)
        xml = get_xml(w._root)
        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
          <protection hidden="1" locked="1"/>
        </styleSheet>
                """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        nft = fonts = borders = fills = Element('empty')
        w._write_cell_xfs(nft, fonts, fills, borders)
        xml = get_xml(w._root)
        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
          <protection hidden="1" locked="1"/>
          <cellXfs count="2">
            <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
            <xf applyProtection="1" borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0">
              <protection hidden="1" locked="1"/>
            </xf>
          </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Exemplo n.º 5
0
    def test_xfs_fills(self):
        st = Style(fill=PatternFill(fill_type='solid',
                                    start_color=Color(colors.DARKYELLOW)))
        self.worksheet.cell('A1').style = st
        w = StyleWriter(self.workbook)
        nft = borders = fonts = DummyElement()
        fills = Element("fills")
        w._write_cell_xfs(nft, fonts, fills, borders)

        xml = get_xml(w._root)
        expected = """ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
        <cellXfs count="2">
          <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
          <xf applyFill="1" borderId="0" fillId="2" fontId="0" numFmtId="0" xfId="0"/>
        </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        expected = """<fills count="3">
            <fill>
              <patternFill patternType="solid">
                <fgColor rgb="00808000"></fgColor>
               </patternFill>
            </fill>
          </fills>
        """
        xml = get_xml(fills)
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_xfs_fills(self):
        st = Style(fill=PatternFill(
            fill_type='solid',
            start_color=Color(colors.DARKYELLOW))
                   )
        self.worksheet.cell('A1').style = st
        w = StyleWriter(self.workbook)
        nft = borders = fonts = DummyElement()
        fills = Element("fills")
        w._write_cell_xfs(nft, fonts, fills, borders)

        xml = tostring(w._root)
        expected = """ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
        <cellXfs count="2">
          <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
          <xf applyFill="1" borderId="0" fillId="2" fontId="0" numFmtId="0" xfId="0"/>
        </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        expected = """<fills count="3">
            <fill>
              <patternFill patternType="solid">
                <fgColor rgb="00808000"></fgColor>
               </patternFill>
            </fill>
          </fills>
        """
        xml = tostring(fills)
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_xfs_fonts(self):
        st = Style(font=Font(size=12, bold=True))
        self.worksheet.cell('A1').style = st
        w = StyleWriter(self.workbook)

        nft = borders = fills = DummyElement()
        fonts = Element("fonts")
        w._write_cell_xfs(nft, fonts, fills, borders)
        xml = unicode(tostring(w._root))
        assert """applyFont="1" """ in xml
        assert """fontId="1" """ in xml

        expected = """
        <fonts count="2">
        <font>
            <sz val="12.0" />
            <color rgb="00000000"></color>
            <name val="Calibri" />
            <family val="2" />
            <b></b>
        </font>
        </fonts>
        """
        xml = tostring(fonts)
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Exemplo n.º 8
0
 def test_protection(self):
     self.worksheet.cell('A1').style.protection.locked = Protection.PROTECTION_UNPROTECTED
     self.worksheet.cell('A1').style.protection.hidden = Protection.PROTECTION_UNPROTECTED
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     assert 'protection' in xml
     assert 'locked="0"' in xml
     assert 'hidden="0"' in xml
Exemplo n.º 9
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)
     ok_('applyAlignment="1"' in xml)
     ok_('horizontal="center"' in xml)
     ok_('vertical="center"' in xml)
Exemplo n.º 10
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.º 11
0
 def test_alignment(self):
     st = Style(alignment=Alignment(horizontal='center', vertical='center'))
     self.worksheet.cell('A1').style = st
     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.º 12
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.º 13
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
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     ok_('textRotation="90"' in xml)
     ok_('textRotation="135"' in xml)
Exemplo n.º 14
0
 def test_protection(self):
     self.worksheet.cell('A1').style = Style(
         protection=Protection(locked=Protection.PROTECTION_UNPROTECTED,
                               hidden=Protection.PROTECTION_UNPROTECTED))
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     assert 'protection' in xml
     assert 'locked="0"' in xml
     assert 'hidden="0"' in xml
Exemplo n.º 15
0
 def test_alignment_rotation(self):
     self.worksheet.cell('A1').style = Style(alignment=Alignment(vertical='center', text_rotation=90))
     self.worksheet.cell('A2').style = Style(alignment=Alignment(vertical='center', text_rotation=135))
     self.worksheet.cell('A3').style = Style(alignment=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.º 16
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
     w = StyleWriter(self.workbook)
     nft = w._write_number_formats()
     w._write_cell_xfs(nft, {}, {}, {})
     xml = get_xml(w._root)
     ok_('textRotation="90"' in xml)
     ok_('textRotation="135"' in xml)
Exemplo n.º 17
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)
     ok_('indent="1"' in xml)
     ok_('indent="4"' in xml)
     #Indents not greater than zero are ignored when writing
     ok_('indent="0"' not in xml)
     ok_('indent="-1"' not in xml)
Exemplo n.º 18
0
 def test_alignment_indent(self):
     self.worksheet.cell('A1').style = Style(alignment=Alignment(indent=1))
     self.worksheet.cell('A2').style = Style(alignment=Alignment(indent=4))
     self.worksheet.cell('A3').style = Style(alignment=Alignment(indent=0))
     self.worksheet.cell('A3').style = Style(alignment=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
Exemplo n.º 19
0
 def test_alignment_rotation(self):
     self.worksheet.cell('A1').style = Style(
         alignment=Alignment(vertical='center', text_rotation=90))
     self.worksheet.cell('A2').style = Style(
         alignment=Alignment(vertical='center', text_rotation=135))
     self.worksheet.cell('A3').style = Style(alignment=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
 def test_default_xfs(self):
     w = StyleWriter(self.workbook)
     fonts = nft = borders = fills = DummyElement()
     w._write_cell_xfs(nft, fonts, fills, borders)
     xml = tostring(w._root)
     expected = """
     <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <cellXfs count="1">
       <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
     </cellXfs>
     </styleSheet>
     """
     diff = compare_xml(xml, expected)
     assert diff is None, diff
Exemplo n.º 21
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
Exemplo n.º 22
0
 def test_default_xfs(self):
     w = StyleWriter(self.workbook)
     fonts = nft = borders = fills = DummyElement()
     w._write_cell_xfs(nft, fonts, fills, borders)
     xml = get_xml(w._root)
     expected = """
     <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <cellXfs count="1">
       <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
     </cellXfs>
     </styleSheet>
     """
     diff = compare_xml(xml, expected)
     assert diff is None, diff
    def test_xfs_borders(self):
        st = Style(border=Border(top=Side(border_style=borders.BORDER_THIN,
                                              color=Color(colors.DARKYELLOW))))
        self.worksheet.cell('A1').style = st
        w = StyleWriter(self.workbook)
        fonts = nft = fills = DummyElement()
        border_node = Element("borders")
        w._write_cell_xfs(nft, fonts, fills, border_node)

        xml = tostring(w._root)
        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
        <cellXfs count="2">
          <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
          <xf applyBorder="1" borderId="1" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
        </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        xml = tostring(border_node)
        expected = """
          <borders count="2">
            <border>
              <left />
              <right />
              <top style="thin">
                <color rgb="00808000"></color>
              </top>
              <bottom />
              <diagonal />
            </border>
          </borders>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Exemplo n.º 24
0
    def test_xfs_borders(self):
        st = Style(border=Border(top=Side(border_style=borders.BORDER_THIN,
                                          color=Color(colors.DARKYELLOW))))
        self.worksheet.cell('A1').style = st
        w = StyleWriter(self.workbook)
        fonts = nft = fills = DummyElement()
        border_node = Element("borders")
        w._write_cell_xfs(nft, fonts, fills, border_node)

        xml = get_xml(w._root)
        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
        <cellXfs count="2">
          <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
          <xf applyBorder="1" borderId="1" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
        </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        xml = get_xml(border_node)
        expected = """
          <borders count="2">
            <border>
              <left />
              <right />
              <top style="thin">
                <color rgb="00808000"></color>
              </top>
              <bottom />
              <diagonal />
            </border>
          </borders>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff