@@ 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