PHPExcel_IOFactory::createReader returns array of pricate properties that i cannot use. (PHPExcel)

10,553

You have to the following to get information from the cells:

$objReader = PHPExcel_IOFactory::createReader( $inputFileType );
$objReader->setLoadSheetsOnly( $sheetname ); // Load specific sheet             
$objPHPExcel = $objReader->canRead( $fileName );
$objPHPExcel = $objReader->load( $fileName );

// Prepare loop to extract values from cells
$worksheet = $objPHPExcel->getActiveSheet();


$cell = $worksheet->getCell( "A1" );
$cell->getValue();
Share:
10,553
Jimmyt1988
Author by

Jimmyt1988

Updated on June 04, 2022

Comments

  • Jimmyt1988
    Jimmyt1988 almost 2 years

    I have the following code (using PHPExcel):

            $inputFileType = 'Excel2007'; 
            $sheetname = 'Upload'; 
            $objReader = PHPExcel_IOFactory::createReader( $inputFileType );
            $objReader->setLoadSheetsOnly( $sheetname ); 
            $objPHPExcel = $objReader->load( $fileName );
    
                foreach( $objPHPExcel->_workSheetCollection as $columnMeta )
                {
                    foreach( $columnMeta->_cellCollection->_cellCache as $columnHeader )
                    {
                        echo $columnHeader->_value;
                    }    
                }
    

    Ofcourse, I cannot actually use the properties or iterate through them because they are private properties of the $objPHPExcel... How do I go about actually get something from this array?

    Snippet of array returned from a print_r:

    [_workSheetCollection:PHPExcel:private] => Array
            (
                [0] => PHPExcel_Worksheet Object
                    (
                        [_parent:PHPExcel_Worksheet:private] => PHPExcel Object
     *RECURSION*
                        [_cellCollection:PHPExcel_Worksheet:private] => PHPExcel_CachedObjectStorage_Memory Object
                            (
                                [_parent:protected] => PHPExcel_Worksheet Object
     *RECURSION*
                                [_currentObject:protected] => 
                                [_currentObjectID:protected] => AG1
                                [_currentCellIsDirty:protected] => 1
                                [_cellCache:protected] => Array
                                    (
                                        [A1] => PHPExcel_Cell Object
    
    • Mark Baker
      Mark Baker over 10 years
      You use the methods that are built into the PHPExcel library, as documented in the documentation and demonstrated in the examples