import openpyxl
wb = openpyxl.load_workbook('example.xlsx')
sheet_names = wb.get_sheet_names()
print(sheet_names)
sheet = wb.get_sheet_by_name('Sheet1')
value = sheet.cell(row=1, column=1).value
print(value)
A warning is displayed.
Call to deprecated function get_sheet_names
(Use wb.sheetnames).sheet_names = wb.get_sheet_names()```
#### **` Call to deprecated function get_sheet_by_name `**
```deprecationwarning
(Use wb[sheetname]).sheet = wb.get_sheet_by_name('Sheet1')```
# solution
Rewrite as follows according to *** Use *** of the warning text.
#### **`sheet_names = wb.sheetnames`**
```sheetnames
```sheet = wb['sheet1']```
```python
import openpyxl
wb = openpyxl.load_workbook('example.xlsx')
sheet_names = wb.sheetnames
print(sheet_names)
sheet = wb['Sheet1']
value = sheet.cell(row=1, column=1).value
print(value)
not recommended! This does not mean that it cannot be used. But if you get a warning, you'll want to fix it.
Recommended Posts