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

PHP: Export sql data to CSV
What is the most efficient way to store emails in mysql
How to access server query string with $_GET from earlier in page?
Magento 1.x: Widget custom parameter
searching certain sql/php tutorials
Class Firebase\JWT\JWT not found
Granting write permissions to DefaultAppPool in Windows is not enough?
Magento Collection wrong result
Are PHPUnit mocking functions still really useful since we can use anonymous classes in PHP7? [closed]
Get rows within 30 days where year is current year, month is current month, day is a string
TCPDF Rotated text in table header over spilling
Error trying to use json_encode() on an array() from mysqli fetch_array()
Eloquent whereRaw statement and orWhereRaw is NULL
How to get an object array's field?
Using Laravel lockForUpdate() while updating Users funds
PHP vTiger6 Issue creating account with vtwsclib

Categories

HOME
openshift
spring-data
events
typelite
angular-ui-grid
enums
subdomain
openlayers-3
odata
mongoid
amp
azure-data-lake
repair
port
solution
slide
alljoyn
parsley.js
watch-os-3
chromecast
webstore
bnf
vmware-workstation
pygobject
hidden
salt-cloud
nullreferenceexception
scheduled-tasks
gitkraken
pst
intel
firemonkey-style
web-config-transform
offline-caching
jackrabbit-oak
amazon-cloudtrail
audit
premake
cloudera-manager
xmlunit
dreamfactory
aurelia-cli
hidden-markov-models
web-inspector
type-inference
music21
ssi
beeline
gestures
htmlspecialchars
dtd
email-injection
controllers
s-function
jsonix
nunit-console
fiber
right-to-left
distributed-cache
polymerfire
gridbaglayout
lovefield
in-app-billing
msgpack
juniper-network-connect
mousehover
fantom
android-handler
ampersand
htmltidy
debug-symbols
fat32
jcheckbox
lifetime
device-admin
windows-rt
tabris
xcode6.3.1
neo4jphp
commenting
preorder
xmi
property-injection
progress-db
application-server
coalesce
disjoint-union
virtual-channel
google-code-prettify
sunstudio
live-wallpaper
getopt-long
autosize
prototypal-inheritance
page-curl
rtd
webresponse
multiple-users
asdoc
yahoo-maps
fxruby
fuzzy-comparison
chronic
rootkit

Resources

Encrypt Message