Read Excel File

Excel file (*.xls files Excel 2003) can be read by MScript. It involves declaring a data set that points to the Excel file and use $getData() function to read the data from the data set.

Below is a simple example that demonstrate this:

<!-- declare data set -->
<dataset id="fileDS" autorewind="true" mode="replace" db="Excel:dataSetFile.xls"/>

<!-- load data from the file -->
<action code="$loadFromDataSource('fileDS')"/>

<!-- read the data from data set -->
<log level="" message="$dataSetInfo('fileDS')"/>
<log msg="reading data: $getData('fileDS','col1')"/>

<!-- advance data set to next row -->
<action code="$nextDataSetRow('fileDS')"/>
<log msg="reading next row: $getData('fileDS','col1')"/>

By detault, the first sheet is read. To read a specific sheet, append the name of the sheet to db attribute as follows:

<dataset id="fileDS" autorewind="true" mode="replace" db="Excel:dataSetFile.xls;mySheetName"/>
QR Code
QR Code accessexcelfile (generated for current page)