Importing data from a Excel file is not difficult. In my project I have 7 fields. One field (Ref_No) is common for the items to be imported . So In the add page i ve selected only Ref_No to be displayed.
You should save your file (in Excel) as xml. (File->Save As->Save As type->XML Spread Sheet )
For this follow the steps as below.
in the Row_Rendered() add this line to the custommsg of the field( in my case Ref_No) where you want a File box.
$this->Ref_No->CustomMsg="</td></tr><tr><td class='ewTableHeader'>File Name</td><td><input type='file' name='file' id='file' /></td></tr>";
2.in the Row_Inserting(&$rs) function add the following code
$data = array();
if ( $_FILES['file']['tmp_name'] )
{
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
foreach ($rows as $row)
{
$field1="";
$field2 = "";
$field3 = "";
$field4= "";
$field5= "";
$field6="";
$index = 1;
$cells = $row->getElementsByTagName( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $field1 = $cell->nodeValue;
if ( $index == 2 ) $field2 = $cell->nodeValue;
if ( $index == 3 ) $field3 = $cell->nodeValue;
if ( $index == 4 ) $field4= $cell->nodeValue;
if ( $index == 5 ) $field5= $cell->nodeValue;
if ( $index == 9 ) $field6=$cell->nodeValue;
$index += 1;
$data []= array('field1'=>$field1,'field2' => $field2,'field3' => $field3, 'field4' => $quantity,'field5' => $field5, 'field6'=>$field6);
}
}
}
$GLOBALS["conn"]->Execute("BEGIN");// so that upload should be complete or no upload
foreach($data as $value)
{
$sInsertSql="insert into tender_rates(field1, field2, field3, field4, Ref_No, field5,field6) values( '".$value['field1']."','".$value['field2']."',". $value['field3'].",". $value['field4'].",'".$rs['Ref_No']."','". $value['field5']."','".$value['field6']."')";
$GLOBALS["conn"]->Execute($sInsertSql);
}
$GLOBALS["conn"]->Execute("COMMIT");