~savoy/ade

84518822838449fc11d0f3a0e24da0a09a28c58b — savoy 2 years ago 3714881
bug: correct pivot formatting if zero columns

Signed-off-by: savoy <git@liberation.red>
2 files changed, 18 insertions(+), 11 deletions(-)

M ade/lib/formatting.py
M ade/lib/remote.py
M ade/lib/formatting.py => ade/lib/formatting.py +16 -9
@@ 43,16 43,20 @@ def adhoc_pivot(
    sht.select()
    app.api.ActiveWindow.DisplayGridlines = False

    freeze_row = rng.end("down").offset(row_offset=1).row
    if not pivot_struct.columns:
        header_left_corner = rng
    else:
        header_left_corner = rng.end("down")

    freeze_row = header_left_corner.offset(row_offset=1).row
    sht.range(f"{freeze_row}:{freeze_row}").select()
    app.api.ActiveWindow.FreezePanes = True
    sht.range((freeze_row, 1)).select()

    title = rng.offset(row_offset=-1)
    title = rng.offset(row_offset=-2)
    title.font.size = 16
    title.value = pivot_struct.name

    header_left_corner = rng.end("down")
    if (number_of_header_columns := len(pivot_struct.columns)) > 1:
        header_right_corner = (
            header_left_corner.end("right")


@@ 76,10 80,13 @@ def adhoc_pivot(
        header.last_cell.offset(column_offset=-(len(pivot_struct.aggfunc) - 1)),
        header.last_cell,
    )
    value_header = sht.range(
        (margin_header.row, index_header.last_cell.offset(column_offset=1).column),
        (margin_header.row, margin_header.column - 1),
    )
    if not pivot_struct.columns:
        value_header = margin_header
    else:
        value_header = sht.range(
            (margin_header.row, index_header.last_cell.offset(column_offset=1).column),
            (margin_header.row, margin_header.column - 1),
        )

    sht.range(title, header.last_cell).font.bold = True
    sht.range(


@@ 99,7 106,7 @@ def adhoc_pivot(

    for idx, head_cell in enumerate(reversed(index_header)):
        step = idx + 1
        if head_cell.value in pivot_struct.subs:
        if head_cell.value in pivot_struct.subs or idx == len(index_header) - 1:
            value_range = sht.range(head_cell, (last_row, head_cell.column))
            for value_cell in value_range:
                str_value = str(value_cell.value)


@@ 111,7 118,7 @@ def adhoc_pivot(
                        [gradient_range[0] - (gradient * step)] * 3
                    )
                    subtotal_range.font.italic = True
                elif value_cell.value == "~All":
                elif value_cell.value in ("~All", "All"):
                    total_range = sht.range(
                        value_cell.address, (value_cell.row, margin_header.column - 1)
                    )

M ade/lib/remote.py => ade/lib/remote.py +2 -2
@@ 2128,7 2128,7 @@ class Compile:

            if collection.subs:
                self.data[collection.name] = DataStructure(
                    SheetStructure(collection.name, "B3"),
                    SheetStructure(collection.name, "B4"),
                    util_data.subtotal(
                        slice_for_pivot,
                        collection.subs,


@@ 2143,7 2143,7 @@ class Compile:
                )
            else:
                self.data[collection.name] = DataStructure(
                    SheetStructure(collection.name, "B3"),
                    SheetStructure(collection.name, "B4"),
                    slice_for_pivot.pivot_table(
                        index=collection.index,
                        columns=collection.columns,