Read the .xlsx file with PHPExcel

1

I'm trying to read the cells in my xlsx file with PHPExcel but I can not get it.

require_once('Classes/PHPExcel.php');
require_once('Classes/PHPExcel/Reader/Excel2007.php');

$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load('C:\xampp\htdocs\hotelplayagolfsitges\wp-content\tesipro.xlsx');

echo 'La celda A2 es: ' . $objPHPExcel->getActiveSheet()->getCell('A2')->getFormattedValue();
echo '<br/>La celda B1 es: ' . $objPHPExcel->getActiveSheet()->getCell('B2')->getCalculatedValue(); 
echo '<br/>La celda B1 es: ' . $objPHPExcel->getActiveSheet()->getCell('C2')->getCalculatedValue(); 

I have this code, the problem is that I do not know whether to use getCalculatedValue() , getValue() , getFormattedValue() or what method to use since I have used them all, but Calculated or Value returns me all the formula, and I do not want the formula, I just want to get the result that is in each cell as seen in Excel.

    
asked by Gemma Pinyol Soto 04.08.2016 в 17:01
source

1 answer

1

You could try to change the path of your .xlsx, put it in the same path where you have your "Classes" libraries. I think he's not managing to find the file. I used it on my localhost and it worked without problems:

<?php
require_once('excel/PHPExcel.php');
require_once('excel/PHPExcel/Reader/Excel2007.php');

$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load('excel\archivo.xlsx');

echo 'La celda A1 es: ' . $objPHPExcel->getActiveSheet()->getCell('A1')->getFormattedValue();
echo '<br/>La celda B1 es: ' . $objPHPExcel->getActiveSheet()->getCell('B1')->getCalculatedValue(); 
echo '<br/>La celda B1 es: ' . $objPHPExcel->getActiveSheet()->getCell('C1')->getCalculatedValue();
?>
    
answered by 08.03.2017 в 00:02