<?php

//  Include PHPExcel_IOFactory
include '../library/Classes/PHPExcel/IOFactory.php';

##this file is in Controllers
##you can write relative path
##EX : ".../upload/products/products.xlsx" THIS IS IN UPLOADS
##I USED IT FIRST IN PRODUCTCONTROLLER.PHP?DO=addproductexcel
##EXAMPLE OF WRITE IN EXCEL IS IN OBGYAPP PROJECT
$inputFileName = 'products.xlsx';

//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    //$objReader->setUTFEncoder('iconv');
    //$objReader::setOutputEncoding('UTF-8');
    $objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}

//  Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
echo $highestRow . "*" . $highestColumn . "<br/>";
//$data = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(0, 1)->getValue();
//  Loop through each row of the worksheet in turn
for ($row = 5; $row <= $highestRow; $row++) {
    //  Read a row of data into an array
    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
//    print_r('<pre>' . 'A' . $row . ':' . $highestColumn . $row);
//    print_r($rowData);
//    print_r('</pre>');
    /* for ($i = 1; $i < count($rowData[0]); $i++) {
      $data = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($x, $y)->getValue();
      print_r('<pre>');
      print_r($row . "," . $i . "=>" . $data);
      print_r('</pre>');
      } */

    //  Insert row data array into your database of choice here
}
