def test_create_string_table(): wb = Workbook() ws = wb.create_sheet() ws.cell('B12').value = 'hello' ws.cell('B13').value = 'world' ws.cell('D28').value = 'hello' table = create_string_table(wb) assert table == ['hello', 'world']
def test_create_string_table(): wb = Workbook() ws = wb.create_sheet() ws.cell('B12').value = 'hello' ws.cell('B13').value = 'world' ws.cell('D28').value = 'hello' table = create_string_table(wb) eq_({'hello': 0, 'world': 1}, table)
def _write_string_table(self, archive): for ws in self.workbook.worksheets: ws.garbage_collect() shared_string_table = create_string_table(self.workbook) archive.writestr(ARC_SHARED_STRINGS, write_string_table(shared_string_table)) return shared_string_table
def test_write_worksheet(): wb = Workbook() ws = wb.create_sheet() ws.cell('F42').value = 'hello' strings = create_string_table(wb) content = write_worksheet(ws, strings, {}) reference_file = os.path.join(DATADIR, 'writer', 'expected', 'sheet1.xml') with open(reference_file) as expected: diff = compare_xml(content, expected.read()) assert diff is None, diff
def test_create_string_table(): from openpyxl.writer.strings import create_string_table wb = Workbook() ws = wb.create_sheet() ws.cell('B12').value = 'hello' ws.cell('B13').value = 'world' ws.cell('D28').value = 'hello' table = create_string_table(wb) assert table == ['hello', 'world']
def test_write_hyperlink(): wb = Workbook() ws = wb.create_sheet() ws.cell('A1').value = "test" ws.cell('A1').hyperlink = "http://test.com" strings = create_string_table(wb) content = write_worksheet(ws, strings, {}) reference_file = os.path.join(DATADIR, 'writer', 'expected', 'sheet1_hyperlink.xml') with open(reference_file) as expected: diff = compare_xml(content, expected.read()) assert diff is None, diff
def test_write_auto_filter_filter_column(): wb = Workbook() ws = wb.worksheets[0] ws.cell('F42').value = 'hello' ws.auto_filter.ref = 'A1:F1' ws.auto_filter.add_filter_column(0, ["0"], blank=True) strings = create_string_table(wb) content = write_worksheet(ws, strings, {}) reference_file = os.path.join(DATADIR, 'writer', 'expected', 'sheet1_auto_filter_filter_column.xml') with open(reference_file) as expected: diff = compare_xml(content, expected.read()) assert diff is None content = write_workbook(wb) reference_file = os.path.join(DATADIR, 'writer', 'expected', 'workbook_auto_filter.xml') with open(reference_file) as expected: diff = compare_xml(content, expected.read()) assert diff is None, diff
def test_write_auto_filter_sort_condition(): wb = Workbook() ws = wb.worksheets[0] ws.cell('A1').value = 'header' ws.cell('A2').value = 1 ws.cell('A3').value = 0 ws.auto_filter.ref = 'A2:A3' ws.auto_filter.add_sort_condition('A2:A3', descending=True) strings = create_string_table(wb) content = write_worksheet(ws, strings, {}) reference_file = os.path.join(DATADIR, 'writer', 'expected', 'sheet1_auto_filter_sort_condition.xml') with open(reference_file) as expected: diff = compare_xml(content, expected.read()) assert diff is None content = write_workbook(wb) reference_file = os.path.join(DATADIR, 'writer', 'expected', 'workbook_auto_filter.xml') with open(reference_file) as expected: diff = compare_xml(content, expected.read())