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.
Unable to print the result in Excel sheet using ID in db.update script
Hi,
I tried to write the result in a excel sheet but I was unable to do with the below script using ID
//excel sheet connection
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=correctpath.xls;readOnly=false", "", "");
if(_containsText(_byId("lnkDownloadXMLfile"), "Download sample file")==true)
{
//write in excel sheet
db.update("update [Sheet1$] set Result='Pass' where ID='TC001'");
}
else
{
db.update("update [Sheet1$] set Result='Fail' where ID='TC001'");
}
I tried to write the result in a excel sheet but I was unable to do with the below script using ID
//excel sheet connection
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=correctpath.xls;readOnly=false", "", "");
if(_containsText(_byId("lnkDownloadXMLfile"), "Download sample file")==true)
{
//write in excel sheet
db.update("update [Sheet1$] set Result='Pass' where ID='TC001'");
}
else
{
db.update("update [Sheet1$] set Result='Fail' where ID='TC001'");
}
Comments
Can you provide some more details?
are you getting any exception on console of sahi?
In path of xls sheet you need to use "\\" . ex. C:\\sahi\\userdata\\scripts\\somefolder\\test.xls
Except than this your script seems proper.It should work.
adding more to Akash's post, your code would look like below mentioned code-
var $SheetName = CurrentTimeDate(); // CurrentTimeDate() -> Custom function
$SheetName = "Result_" + $SheetName;
$db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=C:\\sahi\\userdata\\scripts\\Results.xls;readOnly=false","","");
$db.update("insert into [Sheet1$] (ExecutionResult) values('"+ $SheetName + "')");
$db.update("update [Sheet1$] set Result='Passed' where ExecutionResult='TC01'");
Let us know if you still facing any issues?
-Ashish
what ever the code u have written is correct but u have missed 1 thing that's y u r not able to see the updated XL sheet
1. mention the absolute/ full path of the XL file like below
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=C:\\Documents and Settings\\sivakumar\\Desktop\\orrectpath.xlsx;readOnly=false", "", "");
after executing below step
db.update("update [Sheet1$] set Result='Fail' where ID='TC001'");
u have to apply commit to update the data in database/ XL sheet
i don't have idea about script to commit, pls google it
if u wanna check whether the data is updated in sheet or not with ur code
try with below steps
open the XL sheet and run the script then check the XL sheet then u will find the updated XL Sheet
now u try to close the XL sheet it will ask for save becoz the sheet is updated
I don't think that it requires some external commit to update data.
Steps and query mentioned by ashish are sufficient enough to update/insert data in excel sheet. We are using it in our framework and its working fine [ Without adding any query in script to commit the data.]