1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
  • If PHPExcel is trying to execute that bit of code (you're running an old version by the way) then something in one of those cells is a calculation.... without seeing what calculation it might be trying to execute, I can't tell you why it's doing so – Mark Baker Sep 01 '15 at 09:11
  • Thanks for the heads up, I downloaded the last version from their official website https://phpexcel.codeplex.com/releases/view/119187 so, no idea why it's using a calculation? on the excel file it's a simple cell with text.. – Imnotapotato Sep 01 '15 at 09:31
  • 1
    The latest release is actually the 1.8.1 release from http://github.com/PHPOffice/PHPExcel – Mark Baker Sep 01 '15 at 09:41
  • If a simple cell containing nothing more than plain text is triggering a calculation, then I can't help without doing some diagnostic testing using the actual file in question – Mark Baker Sep 01 '15 at 09:41

1 Answers1

1

You can try rangeToArray()

$objPHPExcel->setActiveSheetIndex(0)->rangeToArray('A1:A15');
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85