Just want to print cell data from excel file. Using PHPExcel?

<?php error_reporting(E_ALL); set_time_limit(0); date_default_timezone_set('Europe/London'); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PHPExcel Reader Example #09</title> </head> <body> <?php /** Include path **/ set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/'); /** PHPExcel_IOFactory */ include 'C:\webserver\www\Classes\PHPExcel\IOFactory.php'; $inputFileType = 'Excel5'; // $inputFileType = 'Excel2007'; // $inputFileType = 'Excel2003XML'; // $inputFileType = 'OOCalc'; // $inputFileType = 'Gnumeric'; $inputFileName = './sampleData/Book1.xls'; $sheetname = 'Data Sheet #3'; class MyReadFilter implements PHPExcel_Reader_IReadFilter { public function readCell($column, $row, $worksheetName = '') { if ($row >= 1 && $row <= 1) { if (in_array($column,range('A','A'))) { return true; } } return false; } } $filterSubset = new MyReadFilter(); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objReader->setLoadSheetsOnly($sheetname); $objReader->setReadFilter($filterSubset); $objPHPExcel = $objReader->load($inputFileName); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); var_dump($sheetData); ?> <body> </html> 

When I run the aboce code, it gives me this output

 array(1) { [1]=> array(1) { ["A"]=> string(6) "ABCDEF" } } 

In the above release, ABCDEF is the first cell data. so I want only ABCDEF not other things as shown above.

+4
source share
2 answers

This is because you asked PHPExcel to provide you with the entire worksheet as an array.

If you just want to use cell value A1:

 $objPHPExcel->getActiveSheet()->getCell('A1')->getValue(); 

instead

 $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); 

Read more about this in the documentation , in this case the file "PHPExcel developer documentation.pdf".

Then you can also completely remove the read filter. Cells are read in a lazy way, so you don’t save anything with a read filter if you still only get access to cell A1.

+4
source

include ' C:\webserver\www\Classes\PHPExcel\IOFactory.php ';

this includes a file that includes the me file in this file.

0
source

All Articles