Reputation: 1653
<?php
$name=$_FILES['u_file']['tmp_name'];
try {
$inputFileType = PHPExcel_IOFactory::identify($name);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($name);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 2; $row <= $highestRow; $row++){
$rowData= $sheet->rangeToArray('A' . $row );
while(list($rno,$atten)=each($rowData[0]))
echo"{$rno} -> {$atten} <br/>";
}
?>
I`m using the above code to print details of a particular column. Is it possible to print details of any 2 columns in the above code? For eg, If I want prints rows belonging to column C and E what should be argument in the rangeToArray Fucntion.
I`m Learning php. Is there any material/documentation for PhpExcel? Or any site that gives description of the various methods and what they do?
Upvotes: 0
Views: 1238
Reputation: 212412
The API docs (found in /Documentation/API, or available online at http://www.cmsws.com/examples/applications/phpexcel/Documentation/API/PHPExcel/PHPExcel.html ) give details of all the classes/methods available in PHPExcel
The rangeToArray() method accepts a standard Excel-style range as a string, with a colon separating the top-left and bottom-right cells of the range (e.g. A1:B2
or A1:A65535
)
EDIT
$rowDataA = ;
$rowDataE = $sheet->rangeToArray('E2:E' . $highestRow);
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_ASSOC);
$mi->attachIterator(new ArrayIterator(
PHPExcel_Calculation_Functions::flattenArray(
$sheet->rangeToArray('A2:A' . $highestRow)
),
'cellA'
);
$mi->attachIterator(new ArrayIterator(
PHPExcel_Calculation_Functions::flattenArray(
$sheet->rangeToArray('E2:E' . $highestRow)
),
'cellE'
);
foreach($mi as $details) {
echo $details['cellA'], ' - ', $details['cellE'], '<br />';
}
if you want to use rangeToArray to get the values:
or
for ($row = 2; $row <= $highestRow; $row++){
$cellA = $sheet->getCell('A' . $row )->getValue();
$cellE = $sheet->getCell('E' . $row )->getValue();
echo "{$cellA} -> {$cellE} <br/>";
}
Upvotes: 2