This is my code so far:
import os
import openpyxl
os.chdir('C:\\Python34\\MyPy')
wb=openpyxl.load_workbook('example.xlsx')
wb.get_sheet_names()
But I get these errors:
Warning (from warnings module):
/File "main", line 1
DeprecationWarning: Call to deprecated function get_sheet_names (Use wb.sheetnames).
['Sheet1', 'Sheet2', 'Sheet3']
Warnings aren't errors - they won't hinder your program from running. In case of deprecated warnings
: you use a feature that will be removed in future versions so the devs lable it deprecated.
It may work now, but next version it may no longer as this feature was removed - then you will get an error.
You can fix it like this:
wb.sheetnames # all names sheet = wb["UseThisSheet"] # select a certain sheet by name for sheet2 in wb: # or go over all sheets print(sheet2.title) sh = wb.active # normally sheet at index 0 if you create an empy one
Source: https://openpyxl.readthedocs.io/en/stable/tutorial.html
Here is a short example on how to create a workbook (my answer to some other xlsx question): https://stackoverflow.com/a/48782382/7505395
Since I bounce around in a few different worksheets in my python, I needed the whole list to work from. I added the following
wbInputFile = load_workbook(inFile)
sheetList = wbInputFile.sheetnames
worksheet = wbInputFile[ sheetList[0] ]
# now I am able to run through the rows and get the info
for row in range(2,worksheet.max_row ):
# get the values for each cell needed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With