Sunday, January 1, 2023

Openpyxl intro,open an existing xlsx and print the number of sheets as well as the first cell's content in the first sheet

 import openpyxl
work_book=openpyxl.load_workbook(r'C:\Users\allso\Desktop\new vba projects\openpyxl\countries.xlsx')
print(work_book.sheetnames)
sheet_obj=work_book['Sheet1']
print(sheet_obj.title)
print(sheet_obj['A1'])
cell=sheet_obj['B1']
print(cell.value)
print(cell.row)
print(cell.column)

No comments:

Post a Comment