I am trying to add an extra sheet to an existing xlsx workbook using openpyxl while keeping the data validation rules. However, when I load the workbook I get the warning:
openpyxl\worksheet_reader.py:312: UserWarning: Data Validation extension is not supported and will be removed
When I add the extra worksheet using this code:
excel_book = openpyxl.load_workbook('SomeSpreadsheet.xlsx' )
with pd.ExcelWriter('SomeSpreadsheet.xlsx', engine='openpyxl') as writer:
writer.book = excel_book
writer.sheets = {
worksheet.title: worksheet
for worksheet in excel_book.worksheets
}
secondMockData = { 'c': [10,20], 'd': [30,40] }
secondMockDF = pd.DataFrame(secondMockData)
secondMockDF.to_excel(writer, 'sheetB', index=False)
writer.save()
The code runs successfully but, as the warning message states, all data validation rules after saving the file. Is there any way around that, or any other way this task can be accomplished (eg, adding the extra worksheet) without losing data validation?
Many thanks in advance