0

Just having a strange issue. I am new in python and while running the below code. Geetting error. I have tried google but unable to run my code. Any advise please

import openpyxl
import os

os.chdir('/Users/omer/Documents/Python_Code/Udemy/Excel_Word_Pdf/')
workbook = openpyxl.load_workbook('example.xlsx')

sheet = workbook.get_sheet_by_name('Sheet1')

workbook.get_sheet_names()

cell = sheet['A1']

And the error i amgetting is

lesson42.py:13: DeprecationWarning: Call to deprecated function get_sheet_by_name (Use wb[sheetname]).
  sheet = workbook.get_sheet_by_name('Sheet1')
lesson42.py:15: DeprecationWarning: Call to deprecated function get_sheet_names (Use wb.sheetnames).
  workbook.get_sheet_names()
2
  • 1
    Instead of sheet = workbook.get_sheet_by_name('Sheet1') can you try sheet = workbook['Sheet1'] Commented Apr 11, 2020 at 0:34
  • It doesnot work . Tried it earlier. Commented Apr 11, 2020 at 0:35

3 Answers 3

1

I just tested the following. This should work.

import openpyxl
import os

workbook = openpyxl.load_workbook('test.xlsx')

sheet = workbook['Sheet1']

print(workbook.sheetnames)

cell = sheet['A1'].value
print(cell)
Sign up to request clarification or add additional context in comments.

Comments

0

DeprecationWarning means that you're calling a function that's no longer supported. Go through their documentation to find the new function that's used to get_name, or try using pandas

Comments

0

Try viewing sheetnames first: workbook.sheetnames

This will give you a list of available sheets, then you can call them with workbook[#Some Sheet]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.