In this example we have a spreadsheet that contains some lookup data:
We want to dynamically query this Excel sheet and find the test data associated with a specific case. For example if we query for "Test2" we want to return back the test data "valuetest2".
The function that will do this uses the built-in Spreadsheet object:
function FindValueFromFile(filename, valueToFind)
//Open the spreadsheet
var success = Spreadsheet.DoAttach(filename, 'Sheet1');
Tester.Assert('Open Spreadsheet', success);
//Now loop through and see if we can find that value
var rowCount = Spreadsheet.GetRowCount();
Spreadsheet.SetRange(2, rowCount + 1, 1, 2);
//Loop through all the rows and find the match
var data = '';
if (Spreadsheet.GetCell(0) == valueToFind)
data = Spreadsheet.GetCell(1);
Attached to this article is a zipfile containg the complete test project.