2. Reading contents of the excel workbook. If the workbook has multiple sheets, is there a way to read contents of a particular sheet by passing the sheet name? For example I have an excel file named properties.xlsx which has 2 sheets: Sheet1 and Sheet2.
If I want to read only contents of Sheet1, how to do that?
The below code which I have written doesn't make sure that only Sheet1 contents are read. It randonmly picks 1 of the sheets and reads it. Maybe its because of the property used: ActiveSheet.
let Excel = getActiveXObject("Excel.Application");
let RowCount = Excel.ActiveSheet.UsedRange.Rows.Count;
let ColumnCount = Excel.ActiveSheet.UsedRange.Columns.Count;
for (let i = 1; i <= RowCount; i++)
let s = "";
for (let j = 1; j <= ColumnCount; j++)
s += (VarToString(Excel.Cells.Item(i, j)) + "\r\n");
Log.Message("Row: " + i, s);
Solved! Go to Solution.
Please keep in mind... this is a TestComplete forum so questions about APIs that are not part of TestComplete... probably not the best place for it.
That said, there are a couple of script extensions you can use that do the comparison.
As for reading Excel via COM, there's plenty of documentation out there for that as it is Microsoft functionality, not TestComplete that you're looking for.
Again, that said... to select a particular sheet, you're going to go off of the Sheets collection of the workbook and apply the sheet name as the index. Check out https://docs.microsoft.com/en-us/office/vba/api/excel.sheets
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider