I have a moderately large xlsx file (around 14 MB) and OpenOffice hangs trying to open it. I was trying to use openpyxl to read the content, following this tutorial. The code snippet is as follows:
from openpyxl import load_workbook wb = load_workbook(filename = 'large_file.xlsx', use_iterators = True) ws = wb.get_sheet_by_name(name = 'big_data')
The problem is, I don't know the sheet name, and Sheet1/Sheet2.. etc. didn't work (returned NoneType object). I could not find a documentation telling me How to get the sheet names for an xlsx files using openpyxl. Can anyone help me?
Read Specific Cells You can access their values by using dictionary-like access: sheet["A2"]. value . Alternatively, you can assign sheet["A2"] to a variable and then do something like cell. value to get the cell's value.
Step 3: Load with Openpyxl Still slow but a tiny drop faster than Pandas. Openpyxl Documentation: Memory use is fairly high in comparison with other libraries and applications and is approximately 50 times the original file size.
Program to read cell value using openpyxl Library in PythonStep1: Import the openpyxl library to the Python program. Step2: Load/Connect the Excel workbook to the program. Step3: Get the title of the default first worksheet of the Workbook. Step4: Create variables and initialize them with the cell names.
Use the sheetnames
property:
sheetnames
Returns the list of the names of worksheets in this workbook.
Names are returned in the worksheets order.
Type: list of strings
print (wb.sheetnames)
You can also get worksheet objects from wb.worksheets
:
ws = wb.worksheets[0]
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