How to select Excel sheet in python?
Hi,
From https://support.smartbear.com/viewarticle/69443/#_ga=1.128686159.2137448148.1449520310
I have python code to read Excel file:
def ReadDataFromExcel():
Excel = Sys.OleObject["Excel.Application"]
Excel.Workbooks.Open("C:\\Work\\TestBook.xls")
RowCount = Excel.ActiveSheet.UsedRange.Rows.Count
ColumnCount = Excel.ActiveSheet.UsedRange.Columns.Count
for i in range(1, RowCount + 1):
s = "";
for j in range(1, ColumnCount + 1):
s = s + VarToString(Excel.Cells.Item[i, j]) + '\r\n'
Log.Message("Row: " + VarToString(i), s);
Excel.Quit();
However I didn't find API how to select a sheet for multiple sheet Excel file? Please advice.
Thanks
Heather
The Sheets collection has to be accessed using Item just like the Cells collection.
For example, your line of code should change to this:
sheet = Excel.Workbooks.open(file).Sheets.Item["Sheet1"]
Hope that helps.