18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Want to store Excel worksheet names in variable.
Hi All,
I am reading and updating Excel sheets using Sahi. As per my scenario, I want to read/update different different worksheets, by passing their names into a common sahi script.
These are the code lines, where I read two worksheets at a time:
$DB_FileValue1 = $db.select("select * from [Sheet1$]");
$DB_FileValue2 = $db.select("select * from [sheet2$]");
Now, when I run the script next time, I want to read another two worksheets. That's why I need to pass worksheet names, through variables. Is it possible with Sahi?
If I have 4 worksheets in an Excel file, say, A,B,C,D. First time, I read A,B and then next time, C,D.
So instead of changing sheet names, everywhere in the code, is it possible that I assign these names to variables?
$Sheet1 = "A";
$Sheet2 = "B"; (Like this?)
Please help in this matter.
I am reading and updating Excel sheets using Sahi. As per my scenario, I want to read/update different different worksheets, by passing their names into a common sahi script.
These are the code lines, where I read two worksheets at a time:
$DB_FileValue1 = $db.select("select * from [Sheet1$]");
$DB_FileValue2 = $db.select("select * from [sheet2$]");
Now, when I run the script next time, I want to read another two worksheets. That's why I need to pass worksheet names, through variables. Is it possible with Sahi?
If I have 4 worksheets in an Excel file, say, A,B,C,D. First time, I read A,B and then next time, C,D.
So instead of changing sheet names, everywhere in the code, is it possible that I assign these names to variables?
$Sheet1 = "A";
$Sheet2 = "B"; (Like this?)
Please help in this matter.
Comments
why don't you encapsulate your whole script in a function worksheet($sheet1, $sheet2){ } and replace $DB_FileValue1 = $db.select("select * from [Sheet1$]") with $DB_FileValue1 = $db.select("select * from "+$sheet1);
Now you could run this script with worksheet("A", "B"); worksheet("C", "D");
Is that what you want?
Regards
Wormi
I tried your suggested approach but that also is not working.
I am having two worksheets named as, "Action" & "Value".
I assigned these names to global variables:
var $sheet1 = "Action";
var $sheet2 = "Value";
and replaced the SELECT query with:
$DB_FileValue1 = $db.select("select * from" + $sheet1);
$DB_FileValue2 = $db.select("select * from" + $sheet2);
But it's not working. Kindly help.
there might be missing a space -> $DB_FileValue1 = $db.select("select * from " + $sheet1)
are there any errors displayed?
I inserted space also, within SELECT query:
$DB_FileValue1 = $db.select("select * from " + $sheet1);
$DB_FileValue2 = $db.select("select * from " + $sheet2);
Below are the Errors, when I try to: _alert($DB_FileValue1);
On Log file:
And on console:
Many thanks for your kind help. I have got the solution.
I assigned worksheet names to variables, in this manner:
var $sheet1 = "[Action$]";
var $sheet2 = "[Value$]";
and now, it is working perfectly.
Approach suggested by you is much appreciated.
regards,
nagar.
Hi globalworming,
It's because of the worksheet name specified.
It should be inside a square bracket and should have a dollar sign after the worksheet name.
I think it is some where missing at DSN creation or in connection string.
var $Db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver = {Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ =
I used..
here and i created a system dsn sample, then where we are using this dsn in connection query.
I think there is a problem on your file directory. Since you used a backslash, there should only be one slash only for each occurrence, If you'll use forward slash (same as with the Sahi documentation), there should be two slashes for each usage
Thanks and regards.
I have replaced the step
but it doesn't work , still i am receiving same error. Can u let me know any other solution.
Thanks and regards,