Learn how to read Excel files in Python: https://blog.aspose.com/2021/12/09/read-excel-files-using-python/
Last active
December 9, 2021 13:26
-
-
Save aspose-com-gists/149106ad8c13c30e1d7c386917442147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Excel workbook | |
wb = Workbook("workbook.xlsx") | |
# Get worksheets collection | |
collection = wb.getWorksheets() | |
collectionCount = collection.getCount() | |
# Loop through all the worksheets | |
for worksheetIndex in range(collectionCount): | |
# Get worksheet using its index | |
worksheet = collection.get(worksheetIndex) | |
# Print worksheet name | |
print("Worksheet: " + str(worksheet.getName())) | |
# Get number of rows and columns | |
rows = worksheet.getCells().getMaxDataRow() | |
cols = worksheet.getCells().getMaxDataColumn() | |
# Loop through rows | |
for i in range(rows): | |
# Loop through each column in selected row | |
for j in range(cols): | |
# Print cell value | |
print(worksheet.getCells().get(i, j).getValue(), end =" | ") | |
# Print line break | |
print("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Excel workbook | |
wb = Workbook("workbook.xlsx") | |
# Get worksheets collection | |
worksheet = wb.getWorksheets().get(0) | |
# Print worksheet name | |
print("Worksheet: " + str(worksheet.getName())) | |
# Get number of rows and columns | |
rows = worksheet.getCells().getMaxDataRow() | |
cols = worksheet.getCells().getMaxDataColumn() | |
# Loop through rows | |
for i in range(rows): | |
# Loop through each column in selected row | |
for j in range(cols): | |
# print cell value | |
print(worksheet.getCells().get(i, j).getValue(), end =" | ") | |
# Print line break | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment