PHPExcel reading columns
- by user1270150
I am new to using the PHPExcel and am struggling to implement a basic reader that can be used to read only specified columns, with all rows from a spreadsheet into an array, which I would like to present in a webpage.
After reading the supplied documentation and examples, I am struggling to wrap my head round the implementation of a number of examples, so any help would be much appreciated.
I am using the following code to get the contents of the default worksheet into an array:
for ($row = 2; $row <= $highestRow; $row++) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$columnHeading = rtrim($columnHeading);
$columnHeading = preg_replace('/\s+/', ' ',$columnHeading);
$columnHeading = preg_replace('/\ /', '_',$columnHeading);
$columnHeading = strtolower($columnHeading);
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
Above code reads through all the columns and rows and builds and array, but I would like to be able to add a configuration array that will declare columns that should be read...sure this is possible, so any help would be much appreciated.
Thanks