18 January 2026:


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

jaganjagan Members
edited November -1 in Sahi - Open Source
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'");
}

Comments

  • Hi Jagan,

    Can you provide some more details?
    I tried to write the result in a excel sheet but I was unable to do with the below script using ID

    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.
  • Hi Jagan,

    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
  • gaveyomgaveyom Members
    edited October 2011
    Hi Jagan,

    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
  • Akss004Akss004 Members
    edited October 2011
    hi gaveyom,

    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.]
Sign In or Register to comment.