PHPExcel reading columns

Posted by user1270150 on Stack Overflow See other posts from Stack Overflow or by user1270150
Published on 2012-11-12T08:59:30Z Indexed on 2012/11/18 17:01 UTC
Read the original article Hit count: 265

Filed under:

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

© Stack Overflow or respective owner

Related posts about phpexcel