From 6b54d5a1034eb0d5ea66d9380e515e013b5338fa Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 12 Oct 2010 21:32:17 +0000 Subject: [PATCH] New examples of Reading Workbooks git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@62184 2327b42d-5241-43d6-9e2a-de5ac946f064 --- .../Examples/Reader/exampleReader01.php | 42 +++++++++ .../Examples/Reader/exampleReader02.php | 50 +++++++++++ .../Examples/Reader/exampleReader03.php | 51 +++++++++++ .../Examples/Reader/exampleReader04.php | 47 ++++++++++ .../Examples/Reader/exampleReader05.php | 51 +++++++++++ .../Examples/Reader/exampleReader06.php | 54 ++++++++++++ .../Examples/Reader/exampleReader07.php | 55 ++++++++++++ .../Examples/Reader/exampleReader08.php | 55 ++++++++++++ .../Examples/Reader/exampleReader09.php | 71 +++++++++++++++ .../Examples/Reader/exampleReader10.php | 82 ++++++++++++++++++ .../Examples/Reader/sampleData/example1.xls | Bin 0 -> 22528 bytes 11 files changed, 558 insertions(+) create mode 100644 Documentation/Examples/Reader/exampleReader01.php create mode 100644 Documentation/Examples/Reader/exampleReader02.php create mode 100644 Documentation/Examples/Reader/exampleReader03.php create mode 100644 Documentation/Examples/Reader/exampleReader04.php create mode 100644 Documentation/Examples/Reader/exampleReader05.php create mode 100644 Documentation/Examples/Reader/exampleReader06.php create mode 100644 Documentation/Examples/Reader/exampleReader07.php create mode 100644 Documentation/Examples/Reader/exampleReader08.php create mode 100644 Documentation/Examples/Reader/exampleReader09.php create mode 100644 Documentation/Examples/Reader/exampleReader10.php create mode 100644 Documentation/Examples/Reader/sampleData/example1.xls diff --git a/Documentation/Examples/Reader/exampleReader01.php b/Documentation/Examples/Reader/exampleReader01.php new file mode 100644 index 00000000..f881af01 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader01.php @@ -0,0 +1,42 @@ + + + + + +PHPExcel Reader Example #01 + + + + +

PHPExcel Reader Example #01

+

Simple File Reader using PHPExcel_IOFactory::load()

+'; +$objPHPExcel = PHPExcel_IOFactory::load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader02.php b/Documentation/Examples/Reader/exampleReader02.php new file mode 100644 index 00000000..51b36e57 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader02.php @@ -0,0 +1,50 @@ + + + + + +PHPExcel Reader Example #02 + + + + +

PHPExcel Reader Example #02

+

Simple File Reader using a Specified Reader

+'; +$objReader = new PHPExcel_Reader_Excel5(); +// $objReader = new PHPExcel_Reader_Excel2007(); +// $objReader = new PHPExcel_Reader_Excel2003XML(); +// $objReader = new PHPExcel_Reader_OOCalc(); +// $objReader = new PHPExcel_Reader_SYLK(); +// $objReader = new PHPExcel_Reader_Gnumeric(); +// $objReader = new PHPExcel_Reader_CSV(); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader03.php b/Documentation/Examples/Reader/exampleReader03.php new file mode 100644 index 00000000..1c571d3c --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader03.php @@ -0,0 +1,51 @@ + + + + + +PHPExcel Reader Example #03 + + + + +

PHPExcel Reader Example #03

+

Simple File Reader using the PHPExcel_IOFactory to Return a Reader

+'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader04.php b/Documentation/Examples/Reader/exampleReader04.php new file mode 100644 index 00000000..a18c7118 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader04.php @@ -0,0 +1,47 @@ + + + + + +PHPExcel Reader Example #04 + + + + +

PHPExcel Reader Example #04

+

Simple File Reader using the PHPExcel_IOFactory to Identify a Reader to Use

+'; + +echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with the identified reader type
'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader05.php b/Documentation/Examples/Reader/exampleReader05.php new file mode 100644 index 00000000..9bee5b47 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader05.php @@ -0,0 +1,51 @@ + + + + + +PHPExcel Reader Example #05 + + + + +

PHPExcel Reader Example #05

+

Simple File Reader using the "Read Data Only" Option

+'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +echo 'Turning Formatting off for Load
'; +$objReader->setReadDataOnly(true); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader06.php b/Documentation/Examples/Reader/exampleReader06.php new file mode 100644 index 00000000..6997a38b --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader06.php @@ -0,0 +1,54 @@ + + + + + +PHPExcel Reader Example #06 + + + + +

PHPExcel Reader Example #06

+

Simple File Reader Loading All WorkSheets

+'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +echo 'Loading all WorkSheets
'; +$objReader->setLoadAllSheets(); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded

'; +$loadedSheetNames = $objPHPExcel->getSheetNames(); +foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { + echo $sheetIndex,' -> ',$loadedSheetName,'
'; +} + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader07.php b/Documentation/Examples/Reader/exampleReader07.php new file mode 100644 index 00000000..0d86ea74 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader07.php @@ -0,0 +1,55 @@ + + + + + +PHPExcel Reader Example #07 + + + + +

PHPExcel Reader Example #07

+

Simple File Reader Loading a Single Named WorkSheet

+'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +echo 'Loading Sheet "',$sheetname,'" only
'; +$objReader->setLoadSheetsOnly($sheetname); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded

'; +$loadedSheetNames = $objPHPExcel->getSheetNames(); +foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { + echo $sheetIndex,' -> ',$loadedSheetName,'
'; +} + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader08.php b/Documentation/Examples/Reader/exampleReader08.php new file mode 100644 index 00000000..c6a44601 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader08.php @@ -0,0 +1,55 @@ + + + + + +PHPExcel Reader Example #08 + + + + +

PHPExcel Reader Example #08

+

Simple File Reader Loading Several Named WorkSheets

+'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "',$sheetnames),'" only
'; +$objReader->setLoadSheetsOnly($sheetnames); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded

'; +$loadedSheetNames = $objPHPExcel->getSheetNames(); +foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) { + echo $sheetIndex,' -> ',$loadedSheetName,'
'; +} + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader09.php b/Documentation/Examples/Reader/exampleReader09.php new file mode 100644 index 00000000..a6cd1442 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader09.php @@ -0,0 +1,71 @@ + + + + + +PHPExcel Reader Example #09 + + + + +

PHPExcel Reader Example #09

+

Simple File Reader Using a Read Filter

+= 1 && $row <= 7) { + if (in_array($column,range('A','E'))) { + return true; + } + } + return false; + } +} + +$filterSubset = new MyReadFilter(); + + +echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +echo 'Loading Sheet "',$sheetname,'" only
'; +$objReader->setLoadSheetsOnly($sheetname); +echo 'Loading Sheet using filter
'; +$objReader->setReadFilter($filterSubset); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/exampleReader10.php b/Documentation/Examples/Reader/exampleReader10.php new file mode 100644 index 00000000..d608c646 --- /dev/null +++ b/Documentation/Examples/Reader/exampleReader10.php @@ -0,0 +1,82 @@ + + + + + +PHPExcel Reader Example #10 + + + + +

PHPExcel Reader Example #10

+

Simple File Reader Using a Configurable Read Filter

+_startRow = $startRow; + $this->_endRow = $endRow; + $this->_columns = $columns; + } + + public function readCell($column, $row, $worksheetName = '') { + if ($row >= $this->_startRow && $row <= $this->_endRow) { + if (in_array($column,$this->_columns)) { + return true; + } + } + return false; + } +} + +$filterSubset = new MyReadFilter(9,15,range('G','K')); + + +echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'
'; +$objReader = PHPExcel_IOFactory::createReader($inputFileType); +echo 'Loading Sheet "',$sheetname,'" only
'; +$objReader->setLoadSheetsOnly($sheetname); +echo 'Loading Sheet using configurable filter
'; +$objReader->setReadFilter($filterSubset); +$objPHPExcel = $objReader->load($inputFileName); + + +echo '
'; + +$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); +var_dump($sheetData); + + +?> + + \ No newline at end of file diff --git a/Documentation/Examples/Reader/sampleData/example1.xls b/Documentation/Examples/Reader/sampleData/example1.xls new file mode 100644 index 0000000000000000000000000000000000000000..a7e0e08ff65235a53c0989d69eced7fc5fbee41f GIT binary patch literal 22528 zcmeHPd2AfldH-g)%R>~kyhO^f#EePVk|>(QIkL z-IJa0O70sU_NWe7hdRt*;N9lbivwJpd=%*_xlXlf*R(^^uPE;~G`&sQ<%$f*g-5cO=?eajijVQr1#UkeOvqb25&t#U>|#u>oNb=RMGA` z;pOhHX6TUybVXQr+hBEhKt0JmX_TIY91$tXb~9F%L6P&Uyx&z#&JP$}DqukE9q0w^ z{6OaXKu>b3Y?h5ISYbO?^-TN%{@Y}$U`SL~1O*~>8BC?R;o(Y!J7tT!xvD~2I;h_k z)oQEDwaRCtd4VB%l56EDSuJwkhJjs!yYJ8C&bgBa=iC{Dp5!|DtaL9yy*1O5Tp^!B z-^n1V9K0%>7#Je|JMU_4k~x=n4rImuk0re}o~$lh!@>z*93^MN>-_ev$|bShiC#Hvph^B2(=knYZpmHiS>_l)PKCcGIiof$Zh zodM}=wm9K=5PR=*VH(-Ug#uflM;07w_WGBA+?So20f4rk#GRgBy5s>o;6DV~!Lm0A z;8327hhc1FN1!!u$FfBL$1nJlIO>(P8PMA+0zToxqR3B9U(#ls%9hA>x;R$wsA;}X z$Y&=}{;WSi!oA*w65Bm;`EtRV!o!~Fa>1iP_D)~C2zX!ap=>FKhy5ilmtz|bWJ@LL zeXuwIiHH30VlmHtJ>nO0ei08xeKdXsB92X$De`y;rep1+)43d)f+tm1OP%o14`qlw zfoc)nRi1vtrXxKj)Q- zn_aZ{WG(v8?wvyeL%VOjW%DN5Y9?E7k7Xa6sm(gH6RbnKHlwX0V-sl49?vTQ*y|Ue zr`jXW4!Ki%df((^7HHGhDWFI5m(i?!Q&S$HQ~nrI3>mcNtY5;>bqFo=rqF#wcYn#p zL^@f3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