Last active
January 12, 2019 19:42
-
-
Save rvzzz/ab274935d31ddb0dff9a3b9f625632bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
from openpyxl import load_workbook | |
workbook_file = load_workbook(filename="test_file_for_data_entry_automation.xlsx", | |
data_only=True, | |
read_only=True) | |
print(workbook_file.sheetnames) # ['Sample-spreadsheet-file', 'Another Sheet'] | |
for sheet in workbook_file: | |
print(sheet.title, "Dimension:", sheet.calculate_dimension()) | |
# Select a worksheet by name: | |
selected_worksheet = workbook_file.active | |
# selected_worksheet = workbook_file['Sample-spreadsheet-file'] | |
print(selected_worksheet.title, "Dimension:", selected_worksheet.calculate_dimension()) | |
# Accessing one cell: | |
print("What's on Cell 'C9' in the 'selected_worksheet'? ->", selected_worksheet["C9"].value) | |
print("Another way to get the value on C9 ->", selected_worksheet.cell(column=3, row=9).value) | |
# ---------------------------------------------------- | |
# Getting ALL the relevant values from a sheet | |
#----------------------------------------------------- | |
# for row in selected_worksheet.rows: | |
# for cell in row: | |
# print(cell.value, end=" | ") | |
# print("\n-------") | |
# ---------------------------------------------------- | |
# exactly the same output as the previous for loop: | |
# ---------------------------------------------------- | |
# for row in selected_worksheet.values: | |
# for value in row: | |
# print(value, end=" | ") | |
# print("\n-------") | |
# ---------------------------------------------------- | |
# Getting only the relevant values from selected range | |
#----------------------------------------------------- | |
for cell_in_range in selected_worksheet['C8':'I10']: | |
for cell in cell_in_range: | |
print(cell.value, type(cell.value), end=" | ") | |
print("\n-------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment