php


Parsing file Excel from PHP


I have a function PHP to parse file Excel, it read all the number of the rows but it doesn't return all the data in the object.
Number of lines 3247, but it return just 1023 lines.
this following the parsing function:
public function parseEquipement($filePath = null) {
set_time_limit(0);
$listEquipement = [];
$count = 0;
$chunkSize = 8192;
$objReader = PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
$spreadsheetInfo = $objReader->listWorksheetInfo($filePath);
$chunkFilter = new \Floose\Parse\ChunkReadFilter();
$objReader->setReadFilter($chunkFilter);
$objReader->setReadDataOnly(true);
$chunkFilter->setRows(0, 1);
$objPHPExcel = $objReader->load($filePath);
$totalRows = $spreadsheetInfo[0]['totalRows'];
for ($startRow = 1; $startRow <= $totalRows; $startRow += $chunkSize) {
$chunkFilter->setRows($startRow, $chunkSize);
$objPHPExcel = $objReader->load($filePath);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, null, true, false);
$startIndex = ($startRow == 1) ? $startRow : $startRow - 1;
if (!empty($sheetData) && $startRow < $totalRows) {
$dataToAnalyse = array_slice($sheetData, $startIndex, $chunkSize);
if($dataToAnalyse[0][0]==NULL){
break;
}
for ($i = 0; $i < $chunkSize; $i++) {
if ($dataToAnalyse[$i]['0'] != NULL) {
$listEquipement[] = new Article($dataToAnalyse[$i]['0'], '', $dataToAnalyse[$i]['1']);
$count++;
}
}
}
//echo($totalRows); // is best
//echo($count); // is wrong
//print_r($listEquipement);
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel, $sheetData);
}
return $listEquipement;
}
I changed all the code by this following but it doesn't work:
public function parseEquipment($filePath = null) {
$objReader = PHPExcel_IOFactory::createReader(PHPExcel_IOFactory::identify($filePath));
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($filePath);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
for ($row = 2; $row <= $highestRow; $row++){
echo $sheet->getCellByColumnAndRow(3, $row)->getCalculatedValue();
echo $sheet->getCellByColumnAndRow(4, $row)->getCalculatedValue();
echo $sheet->getCellByColumnAndRow(2,$row)->getCalculatedValue();
$listEquipement[] = new Article(
$sheet->getCellByColumnAndRow(3, $row)->getCalculatedValue(),
$sheet->getCellByColumnAndRow(4, $row)->getCalculatedValue(),
$sheet->getCellByColumnAndRow(2, $row)->getCalculatedValue()
);
}
}
And when I run my code always it display an error of memory size knowing that the size of my file is 81K and it display the number of lines in the same time.
Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (Tried to allocate 54byte)
Could anyone be kind enough to guide and teach me how I should do my codes or can you suggest me another code to parsing a file Excel ?

Related Links

Android PHP JSON parsing giving 404 error but fetching data
session_start() creates new session every refresh, no warning
Why does date() not convert YYMMDDHHMM to MySQL acceptable date format correctly?
How can I use $POST in PHP to automatically collect data from HTML5 inputs and send through e-mail?
Warning: mysqli_query(): Couldn't fetch mysqli in my code
What is the best way to target older IE browsers with PHP?
Error on displaying the forum data
Laravel 5.1, using variable's name in view files
PDO Code Is not inserting data from Form into MySQL Database
wordpress custom is_front_page logic
Get Last Time User Was Logged In
Magpie: Have multiple images in item, but only want one
Prevent double execution PHP+JS
Generate XML with Phalcon
openshift DB config causing 503
PHP apply “double” even odd classes

Categories

HOME
php
ionic2
activex
loopbackjs
embedded-resource
magento-2.0
jersey-2.0
firebase-database
sharepoint-online
yahoo
l20n
varnish-vcl
akka-persistence
activeadmin
bsd
conda
websphere-portal
ava
dragula
points
history.js
bonita
amazon-iam
substance
es6-modules
dotcms
john-the-ripper
shapeless
om-next
quickcheck
runtimeexception
android-n
flowchart
reverse-dns
asihttprequest
jshint
dredd
ilrepack
msxml
word-2016
d3v4
oracle-fusion-apps
qtextedit
okio
clp
nunit-console
nvda
qtcpsocket
perforce-integrate
psd
jsr363
onepage-checkout
ioctl
voronoi
ajax4jsf
mousehover
lowercase
pythonxy
gql
cache-manifest
algebraixlib
actionpack
scala-swing
python-curses
android-audiomanager
jolie
flurry-analytics
utf8-decode
git-reset
rails-api
fileshare
refit
miglayout
nosql-aggregation
pbkdf2
coalesce
void-pointers
microformats
bcdedit
statechart
tfs-sdk
django-filebrowser
xcode4.5
autosize
django-apps
dynamic-c
expression-web
cewolf
grails-validation
3des
channelfactory
hungarian-notation
self-tracking-entities
efs
version-control-migration

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App