[PYTHON] [Note] Deprecation Warning of OpenPyXL get_sheet_names () and get_sheet_by_name ()

Event

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)

Summary

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

[Note] Deprecation Warning of OpenPyXL get_sheet_names () and get_sheet_by_name ()
About problems and solutions of OpenPyXL (Ver 3.0 version)
It seems that the module of train_test_split changes from 0.20, and Deprecation Warning appears at 0.18.
Mayungo's Python Learning Note: List of stories and links