I have a workbook that I would like to clear a range of values with using OpenPyXI. So far I have the following:
# Import OpenPyXl module.
from openpyxl impo
If you want to truncate (drop and recreate) a whole sheet, including styles, grid styles, everything else you can do it this way:
wb = load_workbook(filename = 'testing.xlsx')
sheet_name = 'AR Cutoff'
# index of [sheet_name] sheet
idx = wb.sheetnames.index(sheet_name)
# remove [sheet_name]
# old versions: wb.remove(writer.book.worksheets[idx])
# for new versions, tested with 3.0.3
ws = wb.get_sheet_by_name(sheet_name)
wb.remove(ws)
# create an empty sheet [sheet_name] using old index
wb.create_sheet(sheet_name, idx)