I load excel file and put into array but some cells in empty so that the array give the error undefined offset 4.
let see some codes
function readExel() {
require_once('Spreadsheet/Excel/Reader/OLERead.php');
require_once('Excel/reader.php');
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1251');
$data->read('exceltestsheet.xls');
$count = count($data->sheets[0]["cells"]);
$returndata = array();
$rows = $data->sheets[0]['numRows'];
$cols = $data->sheets[0]['numCols'];
$i = 0;
for ($x = 2; $x <= $rows; $x++) { // asumes data stat at row 2
for ($y = 1; $y <= $cols; $y++) {

$returndata[$i][$y] = $data->sheets[0]["cells"][$x][$y];

}
$i++;
}
return $returndata;
}
the above function read the file
Regstation No: firstName Surname othername gender
BAED 20903 Kiselya Jacob M
BAED 22617 Abdallah Dotto M
BAED 22618 Abdallah Mzakiru D M
BAED 22619 Abdul Johary D M
so ithe column othername have empty cells so $returdata give the error
so body can help me please?

Comments

nevets’s picture

You could replace

$returndata[$i][$y] = $data->sheets[0]["cells"][$x][$y];

with

$returndata[$i][$y] = !empty($data->sheets[0]["cells"][$x][$y]) ? $data->sheets[0]["cells"][$x][$y] : '';
shirima’s picture

Thanks for you help, now is working