コード例 #1
0
def write_rows(xf, worksheet, string_table, style_table=None):
    """Write worksheet data to xml."""

    # Ensure a blank cell exists if it has a style
    for styleCoord in iterkeys(worksheet._styles):
        if isinstance(styleCoord, str) and COORD_RE.search(styleCoord):
            worksheet.cell(styleCoord)

    # create rows of cells
    cells_by_row = {}
    for cell in itervalues(worksheet._cells):
        cells_by_row.setdefault(cell.row, []).append(cell)

    with xf.element("sheetData"):
        for row_idx in sorted(cells_by_row):
            # row meta data
            row_dimension = worksheet.row_dimensions[row_idx]
            row_dimension.style = worksheet._styles.get(row_idx)
            attrs = {
                'r': '%d' % row_idx,
                'spans': '1:%d' % worksheet.max_column
            }
            attrs.update(dict(row_dimension))

            with xf.element("row", attrs):

                row_cells = cells_by_row[row_idx]
                for cell in sorted(row_cells, key=row_sort):
                    write_cell(xf, worksheet, cell, string_table)
コード例 #2
0
ファイル: worksheet.py プロジェクト: BespokeInsights/openpyxl
def write_format(worksheet):
    attrs = {'defaultRowHeight': '15', 'baseColWidth': '10'}
    dimensions_outline = [dim.outline_level
                          for dim in itervalues(worksheet.column_dimensions)]
    if dimensions_outline:
        outline_level = max(dimensions_outline)
        if outline_level:
            attrs['outlineLevelCol'] = str(outline_level)
    return Element('sheetFormatPr', attrs)
コード例 #3
0
def write_format(worksheet):
    attrs = {'defaultRowHeight': '15', 'baseColWidth': '10'}
    dimensions_outline = [dim.outline_level
                          for dim in itervalues(worksheet.column_dimensions)]
    if dimensions_outline:
        outline_level = max(dimensions_outline)
        if outline_level:
            attrs['outlineLevelCol'] = str(outline_level)
    return Element('sheetFormatPr', attrs)
コード例 #4
0
ファイル: strings.py プロジェクト: jsmojver/Backup_LoboPharm
def create_string_table(workbook):
    """Compile the string table for a workbook."""

    strings = set()
    for sheet in workbook.worksheets:
        for cell in itervalues(sheet._cells):
            if cell.data_type == cell.TYPE_STRING and cell._value is not None:
                strings.add(cell.value)
    return IndexedList(sorted(strings))
コード例 #5
0
def get_rows_to_write(worksheet):
    """Return all rows, and any cells that they contain"""
    # Ensure a blank cell exists if it has a style
    for styleCoord in iterkeys(worksheet._styles):
        if isinstance(styleCoord, str) and COORD_RE.search(styleCoord):
            worksheet.cell(styleCoord)

    # create rows of cells
    cells_by_row = {}
    for cell in itervalues(worksheet._cells):
        cells_by_row.setdefault(cell.row, []).append(cell)

    # make sure rows that only have a height set are returned
    for row_idx in worksheet.row_dimensions:
        if row_idx not in cells_by_row:
            cells_by_row[row_idx] = []

    return cells_by_row
コード例 #6
0
ファイル: test_compat.py プロジェクト: graypools/openpyxl
def test_itervalues(dictionary):
    from openpyxl.compat import itervalues

    d = dictionary
    assert set(itervalues(d)) == set([1, "b", "d"])
コード例 #7
0
def test_itervalues(dictionary):
    from openpyxl.compat import itervalues
    d = dictionary
    assert set(itervalues(d)) == set([1, 'b', 'd'])