Example #1
0
 def test_default_xfs(self):
     w = StyleWriter(self.workbook)
     fonts = nft = borders = fills = DummyElement()
     w._write_cell_styles()
     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
 def test_default_xfs(self):
     w = StyleWriter(self.workbook)
     fonts = nft = borders = fills = DummyElement()
     w._write_cell_styles()
     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
Example #3
0
    def test_xfs_fills(self):
        cell = self.worksheet.cell('A1')
        cell.fill = fill = PatternFill(fill_type='solid',
                                       start_color=Color(colors.DARKYELLOW))
        _ = cell.style_id  # update workbook styles
        w = StyleWriter(self.workbook)
        w._write_cell_styles()

        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 borderId="0" fillId="2" fontId="0" numFmtId="0" xfId="0"/>
          </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Example #4
0
    def test_xfs_fonts(self):
        cell = self.worksheet.cell('A1')
        cell.font = Font(size=12, bold=True)
        _ = cell.style_id  # update workbook styles
        w = StyleWriter(self.workbook)

        w._write_cell_styles()
        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 borderId="0" fillId="0" fontId="1" numFmtId="0" xfId="0"/>
          </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_xfs_fills(self):
        cell = self.worksheet.cell('A1')
        cell.fill = fill=PatternFill(fill_type='solid',
                                     start_color=Color(colors.DARKYELLOW))
        _ = cell.style_id # update workbook styles
        w = StyleWriter(self.workbook)
        w._write_cell_styles()

        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 borderId="0" fillId="2" fontId="0" numFmtId="0" xfId="0"/>
          </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_xfs_fonts(self):
        cell = self.worksheet.cell('A1')
        cell.font = Font(size=12, bold=True)
        _ = cell.style_id # update workbook styles
        w = StyleWriter(self.workbook)

        w._write_cell_styles()
        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 borderId="0" fillId="0" fontId="1" numFmtId="0" xfId="0"/>
          </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Example #7
0
    def test_protection(self):
        cell = self.worksheet.cell('A1')
        cell.protection = Protection(locked=True, hidden=True)
        _ = cell.style_id

        w = StyleWriter(self.workbook)
        w._write_cell_styles()
        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 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
Example #8
0
    def test_xfs_borders(self):
        cell = self.worksheet.cell('A1')
        cell.border = Border(top=Side(border_style=borders.BORDER_THIN,
                                      color=Color(colors.DARKYELLOW)))
        _ = cell.style_id  # update workbook styles

        w = StyleWriter(self.workbook)
        w._write_cell_styles()

        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 borderId="1" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
        </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_protection(self):
        cell = self.worksheet.cell('A1')
        cell.protection = Protection(locked=True, hidden=True)
        _ = cell.style_id

        w = StyleWriter(self.workbook)
        w._write_cell_styles()
        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 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_borders(self):
        cell = self.worksheet.cell('A1')
        cell.border=Border(top=Side(border_style=borders.BORDER_THIN,
                                    color=Color(colors.DARKYELLOW)))
        _ = cell.style_id # update workbook styles

        w = StyleWriter(self.workbook)
        w._write_cell_styles()

        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 borderId="1" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
        </cellXfs>
        </styleSheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Example #11
0
    def test_xfs_number_format(self):
        for idx, nf in enumerate(["0.0%", "0.00%", "0.000%"], 1):
            cell = self.worksheet.cell(row=idx, column=1)
            cell.number_format = nf
            _ = cell.style_id  # add to workbook styles
        w = StyleWriter(self.workbook)
        w._write_cell_styles()

        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
            <cellXfs count="4">
                <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
                <xf borderId="0" fillId="0" fontId="0" numFmtId="164" xfId="0"/>
                <xf borderId="0" fillId="0" fontId="0" numFmtId="10" xfId="0"/>
                <xf borderId="0" fillId="0" fontId="0" numFmtId="165" xfId="0"/>
            </cellXfs>
        </styleSheet>
        """

        xml = tostring(w._root)
        diff = compare_xml(xml, expected)
        assert diff is None, diff
    def test_xfs_number_format(self):
        for idx, nf in enumerate(["0.0%", "0.00%", "0.000%"], 1):
            cell = self.worksheet.cell(row=idx, column=1)
            cell.number_format = nf
            _ = cell.style_id # add to workbook styles
        w = StyleWriter(self.workbook)
        w._write_cell_styles()

        expected = """
        <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
            <cellXfs count="4">
                <xf borderId="0" fillId="0" fontId="0" numFmtId="0" xfId="0"/>
                <xf borderId="0" fillId="0" fontId="0" numFmtId="164" xfId="0"/>
                <xf borderId="0" fillId="0" fontId="0" numFmtId="10" xfId="0"/>
                <xf borderId="0" fillId="0" fontId="0" numFmtId="165" xfId="0"/>
            </cellXfs>
        </styleSheet>
        """

        xml = tostring(w._root)
        diff = compare_xml(xml, expected)
        assert diff is None, diff