Imnotapotato
Imnotapotato

Reputation: 5808

PHPExcel: How to get all column A in an array?

I have this code that I'm using to get all column A as a PHP array:

<?php 

include 'Classes\PHPExcel\IOFactory.php';

$objPHPExcel = PHPExcel_IOFactory::load('keywords.xlsx');

$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);

$arrayCount = count($allDataInSheet);  // Here get total count of row in that Excel sheet

    for( $i=2; $i<=$arrayCount; $i++ )
    {
        $value1 = trim($allDataInSheet[$i]["A"]);       
        var_dump($value1);
    }

?>

It works on one Excel file that has a list of numbers on column A:

Example of an output:

string '111111' (length=6)
string '222222' (length=6)
string '333333' (length=6)
string '444444' (length=6)
string '555555' (length=6)

But when I have a list of texts:

enter image description here

I get an error:

( ! ) Warning: array_keys() expects parameter 1 to be array, integer given in C:\wamp\www\PHPExcel\Classes\PHPExcel\Calculation.php on line 3079

Any idea why this is happening?

Upvotes: 1

Views: 9914

Answers (1)

Abdulla Nilam
Abdulla Nilam

Reputation: 38584

You can try rangeToArray()

$objPHPExcel->setActiveSheetIndex(0)->rangeToArray('A1:A15');

Upvotes: 1

Related Questions