From e7d6547e5665b421be54af084186bb5b4e10eb87 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 8 Sep 2010 13:49:08 +0000 Subject: [PATCH] Applied ReadFilter option to OOCalc and Excel2003XML Readers, plus additional tests in the /Tests directory git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@60573 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Reader/Excel2003XML.php | 82 ++++++++++-------- Classes/PHPExcel/Reader/OOCalc.php | 15 ++-- .../Functionality Cross-Reference.xls | Bin 34816 -> 34816 bytes Tests/Excel2003XMLReader.php | 75 ++++++++++++++++ Tests/Excel2003XMLTest.xml | 1 + Tests/GnumericReader.php | 75 ++++++++++++++++ Tests/GnumericTest.gnumeric | Bin 0 -> 7823 bytes Tests/OOCalcReader.php | 36 ++++++-- Tests/OOCalcTest.ods | Bin 72078 -> 17931 bytes 9 files changed, 233 insertions(+), 51 deletions(-) create mode 100644 Tests/Excel2003XMLReader.php create mode 100644 Tests/Excel2003XMLTest.xml create mode 100644 Tests/GnumericReader.php create mode 100644 Tests/GnumericTest.gnumeric diff --git a/Classes/PHPExcel/Reader/Excel2003XML.php b/Classes/PHPExcel/Reader/Excel2003XML.php index 70e52902..4632860a 100644 --- a/Classes/PHPExcel/Reader/Excel2003XML.php +++ b/Classes/PHPExcel/Reader/Excel2003XML.php @@ -325,43 +325,45 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader $namespaces = $xml->getNamespaces(true); $docProps = $objPHPExcel->getProperties(); - foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) { - switch ($propertyName) { - case 'Title' : - $docProps->setTitle($propertyValue); - break; - case 'Subject' : - $docProps->setSubject($propertyValue); - break; - case 'Author' : - $docProps->setCreator($propertyValue); - break; - case 'Created' : - $creationDate = strtotime($propertyValue); - $docProps->setCreated($creationDate); - break; - case 'LastAuthor' : - $docProps->setLastModifiedBy($propertyValue); - break; - case 'LastSaved' : - $lastSaveDate = strtotime($propertyValue); - $docProps->setModified($lastSaveDate); - break; - case 'Company' : - $docProps->setCompany($propertyValue); - break; - case 'Category' : - $docProps->setCategory($propertyValue); - break; - case 'Manager' : - $docProps->setManager($propertyValue); - break; - case 'Keywords' : - $docProps->setKeywords($propertyValue); - break; - case 'Description' : - $docProps->setDescription($propertyValue); - break; + if (isset($xml->DocumentProperties[0])) { + foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) { + switch ($propertyName) { + case 'Title' : + $docProps->setTitle($propertyValue); + break; + case 'Subject' : + $docProps->setSubject($propertyValue); + break; + case 'Author' : + $docProps->setCreator($propertyValue); + break; + case 'Created' : + $creationDate = strtotime($propertyValue); + $docProps->setCreated($creationDate); + break; + case 'LastAuthor' : + $docProps->setLastModifiedBy($propertyValue); + break; + case 'LastSaved' : + $lastSaveDate = strtotime($propertyValue); + $docProps->setModified($lastSaveDate); + break; + case 'Company' : + $docProps->setCompany($propertyValue); + break; + case 'Category' : + $docProps->setCategory($propertyValue); + break; + case 'Manager' : + $docProps->setManager($propertyValue); + break; + case 'Keywords' : + $docProps->setKeywords($propertyValue); + break; + case 'Description' : + $docProps->setDescription($propertyValue); + break; + } } } if (isset($xml->CustomDocumentProperties)) { @@ -577,6 +579,12 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader } $cellRange = $columnID.$rowID; + if (!is_null($this->getReadFilter())) { + if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) { + continue; + } + } + if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) { $columnTo = $columnID; if (isset($cell_ss['MergeAcross'])) { diff --git a/Classes/PHPExcel/Reader/OOCalc.php b/Classes/PHPExcel/Reader/OOCalc.php index 8dab6c5f..5e8b6197 100644 --- a/Classes/PHPExcel/Reader/OOCalc.php +++ b/Classes/PHPExcel/Reader/OOCalc.php @@ -262,8 +262,6 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']); } foreach($officePropertyDC as $propertyName => $propertyValue) { -// echo $propertyName.' = '.$propertyValue.'
'; - switch ($propertyName) { case 'title' : $docProps->setTitle($propertyValue); @@ -291,13 +289,6 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader } foreach($officePropertyMeta as $propertyName => $propertyValue) { $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']); - -// echo $propertyName.' = '.$propertyValue.'
'; -// foreach ($propertyValueAttributes as $key => $value) { -// echo $key.' = '.$value.'
'; -// } -// echo '
'; -// switch ($propertyName) { case 'initial-creator' : $docProps->setCreator($propertyValue); @@ -384,6 +375,12 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader case 'table-row' : $columnID = 'A'; foreach($rowData as $key => $cellData) { + if (!is_null($this->getReadFilter())) { + if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) { + continue; + } + } + // echo ''.$columnID.$rowID.'
'; $cellDataText = $cellData->children($namespacesContent['text']); $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']); diff --git a/Documentation/Functionality Cross-Reference.xls b/Documentation/Functionality Cross-Reference.xls index fb3821232eb5fa9ebbe5a8b37008666b8663a57e..9a1275e8cc38ee847dba2a0286f952b5368ae4ab 100644 GIT binary patch delta 610 zcmZpez|=5-X@ep&qrl_@7Lmzwn0bj}?E|Yj!>kBY{f=1`Ov+3)VBrL_#3l!@@Po|( z$)lRPg9T>8EjTNHjb#!mNGnJwki*5vu!o6(fq{tuBILjd)x&oOC@RP>fe|WMzzVg1 zkA;zu!2(qm(4fg@;Ksg!nK7A%4dwzpI4c0g;>$oasDTY;1ITJFxYe7FuzBzb8^i(y z8Q2(tGg4Daj9MA^7!FL97g1#l+3YG}qsetRn1SJQBm;wY%w)OvIh)n(0yw1q0u5ne zU}kV;FaTrUFjo}gqZe9?|$-?Z)puc%dNlu=!^jJ0k!k42Ayy delta 555 zcmZpez|=5-X@ep&?>n3S1pz`_Y;iA@e*;Rl-o zl1DXn2Mf%GTX0qY8_OhCkXDdVAcu>SVGk1n0|OHSM96^^s)z3mP*jj%0wYwifE8*1 z9}6QRg9WNCph1(*z>R$cGh;Fj8_WfIa8>|}#g~C{t*Kd zWME?m&PYuyF=}PtW9XPHFQUrmv)NU|Mw7EUn1Nw;Bm;x+<}TZ}9K8F0`k5G*8C-yn zW%4Aq*SYkOHz;CU1^g$n+p~a<}cA$)DmsF%`svn46mt>zF17*jr3W sIm*#{{+_k}X-4MF7gO~4CvUK0*;JAvG7DkE9Kik+D0r(}GFaQ7m diff --git a/Tests/Excel2003XMLReader.php b/Tests/Excel2003XMLReader.php new file mode 100644 index 00000000..58858f06 --- /dev/null +++ b/Tests/Excel2003XMLReader.php @@ -0,0 +1,75 @@ + + + + + +PHPExcel Excel2003XML Reader Test + + + + +load("Excel2003XMLTest.xml"); + + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo '
Call time to read Workbook was '.sprintf('%.4f',$callTime)." seconds
\n"; +// Echo memory usage +echo date('H:i:s').' Current memory usage: '.(memory_get_usage(true) / 1024 / 1024)." MB

\n"; + + +echo date('H:i:s') . " Write to Excel2007 format
"; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); + + +// Echo memory peak usage +echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB
"; + +// Echo done +echo date('H:i:s') . " Done writing file.
"; + +?> + + \ No newline at end of file diff --git a/Tests/Excel2003XMLTest.xml b/Tests/Excel2003XMLTest.xml new file mode 100644 index 00000000..fb2d305c --- /dev/null +++ b/Tests/Excel2003XMLTest.xml @@ -0,0 +1 @@ +3#0000004#0000ff5#0080006#00ccff7#8000808#9933669#c0c0c010#c4751211#ccffcc12#ddbc7d13#ff000014#ff00ff15#ff660016#ff990017#ff99cc18#ffff0090001386024075FalseFalse