~savoy/ade

28b4052c929d615a48e581692c0b8de0d8695f15 — savoy 2 years ago c7e8914
feature: sheets cleared prior to data insertion

The range of potentially pre-existing data already present in a sheet is
now cleared of both its values as well as its formatting. The onus will
be on the template creator therefore to create robust and effective
templates that don't rely on static ranges for formatting, but dynamic.

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