import win32com.client as client
import pathlib
Initialize the application
excel = client.Dispatch('Excel.Application')
Open the file
filepath = r'C:\Users\admin\Documents\personal_income.xlsx'
wb = excel.Workbooks.Open(filepath)
Select the appropiate sheet
sheet = wb.Worksheets[0]
# display the excel program (optional)
excel.Visible=True
Commonly used directional enumerations
- https://docs.microsoft.com/en-us/office/vba/api/excel.xldirection
- https://docs.microsoft.com/en-us/office/vba/api/excel.constants
- https://docs.microsoft.com/en-us/office/vba/api/excel.range.specialcells
xlDown = -4121
xlToLeft = -4159
xlToRight = -4161
xlUp = -4162
xlLastCell = 11
last_cell = sheet.Range('A1').End(xlDown).End(xlToRight)
table_range = sheet.Range('A1', last_cell)
last_cell = sheet.Cells(1, 1).SpecialCells(xlLastCell)
table_range = sheet.Range('A1', last_cell)