I've tried implementing multiple solutions from existing posts, like this one, to no avail: openpyxl Set Active Sheet
I have a workbook with n number of sheets that I want to iteratively step through, and apply header information to. As far as I can tell, using wb.active = i
is setting the active worksheet, but when I follow up with page.append(header)
, I end up with the header appended n times, ONLY to the index 0 sheet. This is essentially the same q as the link above, but the solution doesn't seem to work.
What am I missing here? I wonder if I need to specify an index for page.append()
, but that doesn't seem to be a valid argument for that func.
CODE
header = ['Time [sec]', 'Altitude [km]', 'Velocity [km/s]']
for i in range(len(wb.sheetnames)):
wb.active = i
print(wb.active)
page.append(header)
wb.save(path)
CONSOLE (verifies that the wb.active function is working, but the sheets specified aren't being appended)
<Worksheet "ORB1">
<Worksheet "ORB2">
<Worksheet "ORB3">
<Worksheet "ORB4">
<Worksheet "ORB5">
Here is another version which produces the same result (5x headers applied only to the first sheet).
header = ['Time [sec]', 'Altitude [km]', 'Velocity [km/s]']
for i, s in enumerate(wb.sheetnames):
page.append(header)
wb.save(path)