~savoy/ade

a101e117d1c75027874b1a4650fb7507d2e3dd93 — savoy 3 months ago d022846 feature/custom_structure
feature: data and (maybe) formatting are cleared before insertion

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

M ade/lib/remote.py
M ade/lib/remote.py => ade/lib/remote.py +22 -2
@@ 2787,12 2787,32 @@ class File:
            sht = book.sheets[sht_name]

            rng = sht.range(data_struct.structure.cell)
            # TODO: clear contents by manually getting range (# of rows/columns from DF.clear)
            # full.expand("table").clear_contents()

            if data_struct.pivot:
                num_columns = len(data_struct.data.index[0]) + len(
                    data_struct.data.columns
                )
                num_row_offset = len(data_struct.pivot.columns) + len(
                    data_struct.pivot.values
                )
                num_rows = len(data_struct.data.index) + num_row_offset
                starting_point = rng.offset(row_offset=-num_row_offset)
                ending_point = starting_point.offset(
                    column_offset=num_columns - 1, row_offset=num_rows
                )
                full = sht.range(
                    (starting_point.row, starting_point.column),
                    (ending_point.row, ending_point.column),
                )
            else:
                full = rng.expand("table")

            full.clear_contents()
            rng.value = data_struct.data
            # full.api.AutoFilter(Field=1)

            if data_struct.structure.formatting:
                sht.clear_formats()
                if data_struct.pivot:
                    formatting.adhoc_pivot(
                        app, book, sht, rng, data_struct.data, data_struct.pivot