Top Rounds
|
  1. Explore
    Introduction, screen-shots, features, limitations
  2. Getting started
    Prerequisites, download, install, browser configuration, record, playback, view logs
  3. Sahi Scripting Basics - I
    Statements, variables, functions, conditions and looping, _include
  4. Sahi Scripting Basics - II
  5. Sahi APIs (built-in functions)
    1. Browser Accessor APIs
    2. Browser Action APIs
    3. Miscellaneous APIs
  6. Sahi Scripting - Calling Java
  7. Exception handling using try-catch
  8. Recovering without try-catch using _setRecovery
  9. Data Driven Testing
    _getDB, CSV Files, Excel, Databases
  10. Multithreaded Playback (Parallel execution)
    suites, commandline, ant
  11. Advanced techniques, tips and examples
    1. HTTPS/SSL Sites
    2. Configuring an External proxy
    3. Adding jars to Sahi's classpath
  12. Other language drivers Driving Sahi from Java, Ruby etc.
    1. Java
    2. Ruby
  13. Sahi Pro

Working with Excel Sheets ·

On Windows, you could use the jdbc:odbc driver to access Excel. This does not need any extra jars.

Example:

Given a excel sheet “D:\\sample.xls”, with the following data:

Name Age Sex
Raju 20 Male
Ramu 30 Male
Sheela 25 Female

You can do the following

// Get the DB instance
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", 
"jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=D:\\sample.xls;readOnly=false", 
"", 
"");

// Run a select $rs = db.select("select * from [Sheet1$]");
// Assert the first row has Raju in the Name column _assertEqual("Raju", $rs[0]["Name"]);
// Assert the first row has 20 in the Age column. // All values will be strings, so we need to parseInt the age. _assertEqual(20, parseInt($rs[0]["Age"]));
// Run an update. db.update("update [Sheet1$] set Age=21 where Name='Raju'");
// Do a select again to verify $rs = db.select("select * from [Sheet1$]"); _assertEqual(21, parseInt($rs[0]["Age"]));

Note the readOnly=false in the connection string on the first line.
This is required if you wish to update the Excel sheet.

If you do not add readOnly=false, you will get an error like this:

java.sql.SQLException: [Microsoft][ODBC Excel Driver] Operation must use an 
updateable query.



---


Top Rounds