Reputation: 227
<?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 aboce code it gives me this output
array(1) { [1]=> array(1) { ["A"]=> string(6) "ABCDEF" } }
In above output ABCDEF is first cell data. so i want only ABCDEF not other things as shown above.
Upvotes: 4
Views: 4554
Reputation: 1
include 'C:\webserver\www\Classes\PHPExcel\IOFactory.php
';
this include file which is include by me file in this file.
Upvotes: 0
Reputation: 33678
That is because you asked PHPExcel to give you the whole worksheet as an array.
If you just want the value of cell A1 use:
$objPHPExcel->getActiveSheet()->getCell('A1')->getValue();
instead of
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
More about this in the documentation, in this case the file "PHPExcel developer documentation.pdf".
You can then also remove the read filter altogether. The cells are read in a lazy manner, so you don't save anything with the read filter if you only access cell A1 directly anyway.
Upvotes: 4