Deleting columns corrupts file needing Excel recovery
Hi,
Thanks for your work in maintaining this project.
Versions: Openpyxl 3.0.7, Python 3.8, Windows 10, Excel 2013
I intend to delete some columns from a template and save a new version. However, deleting the columns makes the file need recovery and gets corrupted I suppose.
I'm making sure to delete the columns from right to left. Sample code below:
import time
from openpyxl import load_workbook
EXCEL_FILE = "client-sample.xlsx"
SAVE_FILENAME = "client-sample-{timestamp}.xlsx"
def delete_columns():
wb = load_workbook(EXCEL_FILE)
sheet = wb.active
for col in [17, 16]:
sheet.delete_cols(col)
wb.save(SAVE_FILENAME.format(timestamp=time.strftime("%Y%m%d-%H%M%S")))
What I noticed is when excel prompts and recovers the file, it tries to retain the number of columns the file had before by creating new columns.
There are also no formulas/validations in columns to delete.
Is there anything I'm doing wrong? Files attached.
Thanks for your help.
client-sample-20210406-212935.xlsx