PHPExcel How to get only 1 cell value?

前端 未结 3 1543
误落风尘
误落风尘 2020-12-09 16:55

I would think that a getCell($X, $y) or getCellValue($X, $y) would be available for one to easily pick a a certain value. This can be usefully, as

3条回答
  •  一整个雨季
    2020-12-09 17:56

    By far the simplest - and it uses normal Excel co-ordinates:

    // Assuming $sheet is a PHPExcel_Worksheet
    
    $value = $sheet->getCell( 'A1' )->getValue();
    

    You can separate the co-ordinates out in a function if you like:

    function getCell( PHPExcel_Worksheet $sheet, /* string */ $x = 'A', /* int */ $y = 1 ) {
    
        return $sheet->getCell( $x . $y );
    
    }
    
    // eg:
    getCell( $sheet, 'B', 2 )->getValue();
    

提交回复
热议问题