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.

Updating Text Data in Excel

gunjangunjan Members
edited November -1 in Sahi - Open Source
I am Trying to update Text Data (Name) using Sahi script the data is stored in Excel file. I want to update name from 'Raman' to 'Ram'

Here is the sample data stored in Excel

Name Age Sex
Raju 21 Male
Raman 30 Male
Sheela 23 Female

I am using following script

// Get the DB instance
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=C:\\Test Data\\abc.xls;readOnly=false", "", "");

var $rs = db.select("select * from [Sheet1$]");


var $data1 =($rs[1]["name"]); //name of the column
var $data2 =($rs[1]["age"]); //name of the column
var $data3 =($rs[1]["sex"]); //name of the column


_assertEqual("Raman", $rs[1]["Name"]);
_assertEqual(30, parseInt($rs[1]["Age"]));
_assertEqual("Male", $rs[1]["Sex"]);



db.update("update [Sheet1$] set Name='Ram' where Age=30");
$rs = db.select("select * from [Sheet1$]");
_assertEqual("Ram", $rs[1]["Name"]);

I am getting following error:


Error:

Starting script
_assertEqual("Raman", "Raman"); at Oct 20, 2011 4:04:54 PM
_assertEqual(30, parseInt("30")); at Oct 20, 2011 4:04:56 PM
_assertEqual("Male", "Male"); at Oct 20, 2011 4:04:57 PM
_assertEqual("Ram", "Raman");
Assertion Failed.
Expected:[Ram]
Actual:[Raman] at Oct 20, 2011 4:05:08 PM
Stopping script

I am using Windows 7, Firefox 6.0.2 and Sahi v3.5

Please help me to resolve this.

Thanks,
Gunjan

Comments

  • Hi gunjan,

    Check the file permission.

    Try again by closing all instances of that file or just create new file with same data.

    [Might be some other process has locked instance of that file]. Which is not allowing script to update excel sheet.



    Otherwise code seems proper and its working without changing any syntax on my system.
  • Thank u so much. It work fine on other system.
This discussion has been closed.