def test_merge_range_string(self):
     ws = Worksheet(self.wb)
     ws['A1'] = 1
     ws['D4'] = 16
     ws.merge_cells(range_string="A1:D4")
     assert ws._merged_cells == ["A1:D4"]
     assert 'D4' not in ws._cells
 def test_merge_range_string(self):
     ws = Worksheet(self.wb)
     ws['A1'] = 1
     ws['D4'] = 16
     ws.merge_cells(range_string="A1:D4")
     assert ws._merged_cells == ["A1:D4"]
     assert 'D4' not in ws._cells
Ejemplo n.º 3
0
def copyCellFormat(cellsrc:Cell, sheetSrc:Worksheet, celldest:Cell, sheetDes:Worksheet):
    celldest.fill = copy(cellsrc.fill)
    celldest.font = copy(cellsrc.font)
    celldest.border = copy(cellsrc.border)
    celldest.alignment = copy(cellsrc.alignment)
    celldest.number_format = copy(cellsrc.number_format)
    celldest.protection = copy(cellsrc.protection)

    for merged_cell in sheetSrc.merged_cells:
        if merged_cell.min_col==cellsrc.col_idx and merged_cell.min_row==cellsrc.row:
            sheetDes.merge_cells(start_row= celldest.row, end_row= celldest.row,
                                 start_column= merged_cell.min_col, end_column= merged_cell.max_col)
            break
Ejemplo n.º 4
0
    def test_merge(self):
        ws = Worksheet(self.wb)
        string_table = {'': '', 'Cell A1': 'Cell A1', 'Cell B1': 'Cell B1'}

        ws.cell('A1').value = 'Cell A1'
        ws.cell('B1').value = 'Cell B1'
        xml_string = write_worksheet(ws, string_table, None)
        assert '<v>Cell B1</v>' in xml_string

        ws.merge_cells('A1:B1')
        xml_string = write_worksheet(ws, string_table, None)
        assert '<v>Cell B1</v>' not in xml_string
        assert '<mergeCells count="1"><mergeCell ref="A1:B1"></mergeCell></mergeCells>' in xml_string

        ws.unmerge_cells('A1:B1')
        xml_string = write_worksheet(ws, string_table, None)
        assert '<mergeCell ref="A1:B1"/>' not in xml_string
Ejemplo n.º 5
0
    def test_merge(self):
        ws = Worksheet(self.wb)
        string_table = {'':'', 'Cell A1':'Cell A1','Cell B1':'Cell B1'}

        ws.cell('A1').value = 'Cell A1'
        ws.cell('B1').value = 'Cell B1'
        xml_string = write_worksheet(ws, string_table, None)
        assert '<c r="B1" t="s"><v>Cell B1</v></c>' in xml_string

        ws.merge_cells('A1:B1')
        xml_string = write_worksheet(ws, string_table, None)
        assert '<c r="B1" t="s"><v>Cell B1</v></c>' not in xml_string
        assert '<mergeCells><mergeCell ref="A1:B1"></mergeCell></mergeCells>' in xml_string

        ws.unmerge_cells('A1:B1')
        xml_string = write_worksheet(ws, string_table, None)
        assert '<mergeCell ref="A1:B1"></mergeCell>' not in xml_string
 def test_merge_coordinate(self):
     ws = Worksheet(self.wb)
     ws.merge_cells(start_row=1, start_column=1, end_row=4, end_column=4)
     assert ws._merged_cells == ["A1:D4"]
 def test_merge_coordinate(self):
     ws = Worksheet(self.wb)
     ws.merge_cells(start_row=1, start_column=1, end_row=4, end_column=4)
     assert ws._merged_cells == ["A1:D4"]
Ejemplo n.º 8
0
    def test_merge(self):
        ws = Worksheet(self.wb)
        string_table = {'':'', 'Cell A1':'Cell A1', 'Cell B1':'Cell B1'}
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr defaultRowHeight="15"/>
          <cols>
            <col min="1" max="1" width="9.10"/>
            <col min="2" max="2" width="9.10"/>
          </cols>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>Cell A1</v>
              </c>
              <c r="B1" t="s">
                <v>Cell B1</v>
              </c>
            </row>
          </sheetData>
        </worksheet>
        """

        ws.cell('A1').value = 'Cell A1'
        ws.cell('B1').value = 'Cell B1'
        xml = write_worksheet(ws, string_table, None)
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        ws.merge_cells('A1:B1')
        xml = write_worksheet(ws, string_table, None)
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr defaultRowHeight="15"/>
          <cols>
            <col min="1" max="1" width="9.10"/>
            <col min="2" max="2" width="9.10"/>
          </cols>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>Cell A1</v>
              </c>
              <c r="B1" t="s"/>
            </row>
          </sheetData>
          <mergeCells count="1">
            <mergeCell ref="A1:B1"/>
          </mergeCells>
        </worksheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        ws.unmerge_cells('A1:B1')
        xml = write_worksheet(ws, string_table, None)
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr defaultRowHeight="15"/>
          <cols>
            <col min="1" max="1" width="9.10"/>
            <col min="2" max="2" width="9.10"/>
          </cols>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>Cell A1</v>
              </c>
              <c r="B1" t="s"/>
            </row>
          </sheetData>
        </worksheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Ejemplo n.º 9
0
    def test_merge(self):
        ws = Worksheet(self.wb)
        string_table = ['Cell A1', 'Cell B1']
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>0</v>
              </c>
              <c r="B1" t="s">
                <v>1</v>
              </c>
            </row>
          </sheetData>
          <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
        </worksheet>
        """

        ws.cell('A1').value = 'Cell A1'
        ws.cell('B1').value = 'Cell B1'
        xml = write_worksheet(ws, string_table, None)
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        ws.merge_cells('A1:B1')
        xml = write_worksheet(ws, string_table, None)
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>0</v>
              </c>
              <c r="B1" t="s"/>
            </row>
          </sheetData>
          <mergeCells count="1">
            <mergeCell ref="A1:B1"/>
          </mergeCells>
          <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
        </worksheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        ws.unmerge_cells('A1:B1')
        xml = write_worksheet(ws, string_table, None)
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>0</v>
              </c>
              <c r="B1" t="s"/>
            </row>
          </sheetData>
          <pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
        </worksheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff
Ejemplo n.º 10
0
    def test_merge(self):
        ws = Worksheet(self.wb)
        string_table = {'': '', 'Cell A1': 'Cell A1', 'Cell B1': 'Cell B1'}
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr defaultRowHeight="15"/>
          <cols>
            <col min="1" max="1" width="9.10"/>
            <col min="2" max="2" width="9.10"/>
          </cols>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>Cell A1</v>
              </c>
              <c r="B1" t="s">
                <v>Cell B1</v>
              </c>
            </row>
          </sheetData>
        </worksheet>
        """

        ws.cell('A1').value = 'Cell A1'
        ws.cell('B1').value = 'Cell B1'
        xml = write_worksheet(ws, string_table, None)
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        ws.merge_cells('A1:B1')
        xml = write_worksheet(ws, string_table, None)
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr defaultRowHeight="15"/>
          <cols>
            <col min="1" max="1" width="9.10"/>
            <col min="2" max="2" width="9.10"/>
          </cols>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>Cell A1</v>
              </c>
              <c r="B1" t="s"/>
            </row>
          </sheetData>
          <mergeCells count="1">
            <mergeCell ref="A1:B1"/>
          </mergeCells>
        </worksheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff

        ws.unmerge_cells('A1:B1')
        xml = write_worksheet(ws, string_table, None)
        expected = """
        <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
          <sheetPr>
            <outlinePr summaryRight="1" summaryBelow="1"/>
          </sheetPr>
          <dimension ref="A1:B1"/>
          <sheetViews>
            <sheetView workbookViewId="0">
              <selection sqref="A1" activeCell="A1"/>
            </sheetView>
          </sheetViews>
          <sheetFormatPr defaultRowHeight="15"/>
          <cols>
            <col min="1" max="1" width="9.10"/>
            <col min="2" max="2" width="9.10"/>
          </cols>
          <sheetData>
            <row r="1" spans="1:2">
              <c r="A1" t="s">
                <v>Cell A1</v>
              </c>
              <c r="B1" t="s"/>
            </row>
          </sheetData>
        </worksheet>
        """
        diff = compare_xml(xml, expected)
        assert diff is None, diff