def test_write_number_formats(): wb = DummyWorkbook() wb._number_formats = ['YYYY'] writer = StyleWriter(wb) writer._write_number_formats() xml = tostring(writer._root) expected = """ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <numFmts count="1"> <numFmt formatCode="YYYY" numFmtId="164"></numFmt> </numFmts> </styleSheet> """ diff = compare_xml(xml, expected) assert diff is None, diff
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)
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
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
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
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
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)
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
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_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)
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
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
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