kifield/kifield.py
def group_wb(wb, no_range=False):
    """Group lines that have the same column values in a openpyxl workbook.
    Headers are expected on the first row and references are expected in the
    first column."""

    ws = wb.active
    values = tuple(ws.values)

    try:
        header = values[0]
    except IndexError:
        # No header, so don't even try to ungroup the workbook.
        return wb

    unique_rows = []
    references = []
    for row in values[1:]:
        column_values = row[1:]
        reference = row[0]
        if column_values in unique_rows:
            index = unique_rows.index(column_values)
            references[index].append(reference)
        else:
            unique_rows.append(column_values)
            references.append([reference])

    grouped_rows = []
    for i, ref in enumerate(references):
        # If no_range flag, do the collapse to ensure sorting, then explode, then join to string
        if no_range:
            collapsed_refs = collapse(ref)
            exploded_refs = explode(collapsed_refs)
            joined_refs = (', ').join(exploded_refs)
            grouped_rows.append((joined_refs,) + unique_rows[i])
        else:
            grouped_rows.append((collapse(ref),) + unique_rows[i])

    grouped_wb = pyxl.Workbook()
    grouped_ws = grouped_wb.active
    grouped_ws.append(header)

    for row in grouped_rows:
        grouped_ws.append(row)

    return grouped_wb
Group lines that have the same column values in a openpyxl workbook.
    Headers are expected on the first row and references are expected in the
    first column.
Group lines that have the same column values in a openpyxl workbook.
Headers are expected on the first row and references are expected in the
first column.
Group lines that have the same column values in a openpyxl workbook . Headers are expected on the first row and references are expected in the first column .
def group_wb(wb, no_range=False):
    ws = wb.active
    values = tuple(ws.values)
    try:
        header = values[0]
    except IndexError:
        return wb
    unique_rows = []
    references = []
    for row in values[1:]:
        column_values = row[1:]
        reference = row[0]
        if column_values in unique_rows:
            index = unique_rows.index(column_values)
            references[index].append(reference)
        else:
            unique_rows.append(column_values)
            references.append([reference])
    grouped_rows = []
    for i, ref in enumerate(references):
        if no_range:
            collapsed_refs = collapse(ref)
            exploded_refs = explode(collapsed_refs)
            joined_refs = (', ').join(exploded_refs)
            grouped_rows.append((joined_refs,) + unique_rows[i])
        else:
            grouped_rows.append((collapse(ref),) + unique_rows[i])
    grouped_wb = pyxl.Workbook()
    grouped_ws = grouped_wb.active
    grouped_ws.append(header)
    for row in grouped_rows:
        grouped_ws.append(row)
    return grouped_wb
def group_wb ( wb , no_range = False ) : ws = wb . active values = tuple ( ws . values ) try : header = values [ 0 ] except IndexError : return wb unique_rows = [ ] references = [ ] for row in values [ 1 : ] : column_values = row [ 1 : ] reference = row [ 0 ] if column_values in unique_rows : index = unique_rows . index ( column_values ) references [ index ] . append ( reference ) else : unique_rows . append ( column_values ) references . append ( [ reference ] ) grouped_rows = [ ] for i , ref in enumerate ( references ) : if no_range : collapsed_refs = collapse ( ref ) exploded_refs = explode ( collapsed_refs ) joined_refs = ( ', ' ) . join ( exploded_refs ) grouped_rows . append ( ( joined_refs , ) + unique_rows [ i ] ) else : grouped_rows . append ( ( collapse ( ref ) , ) + unique_rows [ i ] ) grouped_wb = pyxl . Workbook ( ) grouped_ws = grouped_wb . active grouped_ws . append ( header ) for row in grouped_rows : grouped_ws . append ( row ) return grouped_wb
Group lines that have the same column values in a openpyxl workbook.
Group lines that have the same column values in a openpyxl workbook .
"""Group lines that have the same column values in a openpyxl workbook.
    Headers are expected on the first row and references are expected in the
    first column.""" # No header, so don't even try to ungroup the workbook. # If no_range flag, do the collapse to ensure sorting, then explode, then join to string
wb
no_range