I have an existing XLSX workbook with multiple sheets. This short script cycles through all the worksheets and hides columns 'F' and 'G':
import openpyxl from openpyxl import load_workbook
workbook = load_workbook('Example.xlsx') sheets = workbook.sheetnames workbook.close
for wname in sheets: wb = load_workbook('Example.xlsx') ws = wb[wname] wb.active = ws for tempwname in sheets: if tempwname != wname and tempwname != "Code_cat_perso": del wb[tempwname] if tempwname == wname and tempwname != "Code_cat_perso": for col in ['F', 'G']: ws.column_dimensions[col].hidden= True outputname = "tmp-"+ wname + ".xlsx" wb.save(outputname) wb.close
I want to create separate workbooks for each worksheet... except for the worksheet named 'Code_cat_perso' with columns 'F' and 'G' hidden.
The workbooks are created... one for each worksheet. But for some reason, the two columns are only hidden if I read them with Excel 2016. In LibreOffice 6.2.2, the columns are not hidden.
Am I doing something wrong? Or is this just a LibreOffice bug and I'm not posting this in the proper place?