Get data from one cell.

Topics: User Forum
Oct 8, 2008 at 4:44 PM
Hi Guys,

Great bit of software you've written here. I've a question but couldn't find my answer anywhere...

I'm trying to use it to read one specific cell in a spreadsheet (and maybe assign it to a string in PHP). Is this possible or is the software more designed to write spreadsheets rather than read the data?

Kind regards,

-Chris
Developer
Oct 8, 2008 at 5:06 PM
This should be quite straightforward. Use 'Excel2007' if you need to read xlsx, use 'Excel5' if you need to read xls

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$reader->setReadDataOnly(true);

$excel = $reader->load('test.xlsx');
$sheet = $PHPExcel->getActiveSheet();

$string = $sheet->getCell('A1')->getValue();
var_dump($string);

Oct 8, 2008 at 5:09 PM
Perfect.. Exactly what I needed..

Will the functions be processed in those cells?

Thank you again.

-Chris
Developer
Oct 8, 2008 at 5:32 PM
If you want processed results, you need this instead:

$string = $sheet->getCell('A1')->getCalculatedValue();