From ef5cabe532311dd7624a64aeb8c82740f2bc1b89 Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 10 Mar 2024 15:43:07 +0000 Subject: [PATCH] Dateien nach "includes/PHPExcel/Examples" hochladen --- includes/PHPExcel/Examples/.gitignore | 3 + includes/PHPExcel/Examples/01pharSimple.php | 112 +++++ .../Examples/01simple-download-ods.php | 89 ++++ .../Examples/01simple-download-pdf.php | 104 ++++ .../Examples/01simple-download-xls.php | 89 ++++ .../Examples/01simple-download-xlsx.php | 89 ++++ includes/PHPExcel/Examples/01simple.php | 118 +++++ includes/PHPExcel/Examples/01simplePCLZip.php | 106 +++++ includes/PHPExcel/Examples/02types-xls.php | 183 +++++++ includes/PHPExcel/Examples/02types.php | 183 +++++++ includes/PHPExcel/Examples/03formulas.php | 149 ++++++ includes/PHPExcel/Examples/04printing.php | 125 +++++ .../PHPExcel/Examples/05featuredemo.inc.php | 394 +++++++++++++++ includes/PHPExcel/Examples/05featuredemo.php | 78 +++ .../06largescale-with-cellcaching-sqlite.php | 129 +++++ .../06largescale-with-cellcaching-sqlite3.php | 129 +++++ .../06largescale-with-cellcaching.php | 128 +++++ .../PHPExcel/Examples/06largescale-xls.php | 136 ++++++ includes/PHPExcel/Examples/06largescale.php | 136 ++++++ includes/PHPExcel/Examples/07reader.php | 76 +++ includes/PHPExcel/Examples/07readerPCLZip.php | 79 +++ .../Examples/08conditionalformatting.php | 189 ++++++++ .../Examples/08conditionalformatting2.php | 136 ++++++ includes/PHPExcel/Examples/09pagebreaks.php | 134 ++++++ .../Examples/10autofilter-selection-1.php | 221 +++++++++ .../Examples/10autofilter-selection-2.php | 213 +++++++++ .../10autofilter-selection-display.php | 198 ++++++++ includes/PHPExcel/Examples/10autofilter.php | 171 +++++++ .../Examples/11documentsecurity-xls.php | 109 +++++ .../PHPExcel/Examples/11documentsecurity.php | 109 +++++ .../PHPExcel/Examples/12cellProtection.php | 107 +++++ includes/PHPExcel/Examples/13calculation.php | 235 +++++++++ includes/PHPExcel/Examples/14excel5.php | 63 +++ .../Examples/15datavalidation-xls.php | 142 ++++++ .../PHPExcel/Examples/15datavalidation.php | 143 ++++++ includes/PHPExcel/Examples/16csv.php | 107 +++++ includes/PHPExcel/Examples/17html.php | 64 +++ .../Examples/18extendedcalculation.php | 108 +++++ includes/PHPExcel/Examples/19namedrange.php | 129 +++++ includes/PHPExcel/Examples/20readexcel5.php | 79 +++ includes/PHPExcel/Examples/21pdf.php | 94 ++++ .../PHPExcel/Examples/22heavilyformatted.php | 116 +++++ includes/PHPExcel/Examples/23sharedstyles.php | 124 +++++ includes/PHPExcel/Examples/24readfilter.php | 77 +++ .../PHPExcel/Examples/25inmemoryimage.php | 83 ++++ includes/PHPExcel/Examples/26utf8.php | 122 +++++ includes/PHPExcel/Examples/27imagesexcel5.php | 64 +++ includes/PHPExcel/Examples/28iterator.php | 68 +++ .../Examples/29advancedvaluebinder.php | 183 +++++++ includes/PHPExcel/Examples/30template.php | 91 ++++ .../Examples/31docproperties_write-xls.php | 119 +++++ .../Examples/31docproperties_write.php | 119 +++++ .../PHPExcel/Examples/32chartreadwrite.php | 131 +++++ .../PHPExcel/Examples/33chartcreate-area.php | 142 ++++++ .../Examples/33chartcreate-bar-stacked.php | 145 ++++++ .../PHPExcel/Examples/33chartcreate-bar.php | 145 ++++++ .../Examples/33chartcreate-column-2.php | 154 ++++++ .../Examples/33chartcreate-column.php | 145 ++++++ .../Examples/33chartcreate-composite.php | 203 ++++++++ .../PHPExcel/Examples/33chartcreate-line.php | 142 ++++++ .../33chartcreate-multiple-charts.php | 220 +++++++++ .../PHPExcel/Examples/33chartcreate-pie.php | 215 +++++++++ .../PHPExcel/Examples/33chartcreate-radar.php | 154 ++++++ .../Examples/33chartcreate-scatter.php | 138 ++++++ .../PHPExcel/Examples/33chartcreate-stock.php | 151 ++++++ includes/PHPExcel/Examples/34chartupdate.php | 78 +++ includes/PHPExcel/Examples/35chartrender.php | 134 ++++++ .../Examples/36chartreadwriteHTML.php | 151 ++++++ .../PHPExcel/Examples/36chartreadwritePDF.php | 174 +++++++ .../PHPExcel/Examples/37page_layout_view.php | 83 ++++ .../PHPExcel/Examples/38cloneWorksheet.php | 118 +++++ includes/PHPExcel/Examples/39dropdown.php | 175 +++++++ .../PHPExcel/Examples/40duplicateStyle.php | 51 ++ includes/PHPExcel/Examples/41password.php | 84 ++++ includes/PHPExcel/Examples/42richText.php | 159 +++++++ .../PHPExcel/Examples/Excel2003XMLReader.php | 61 +++ .../PHPExcel/Examples/Excel2003XMLTest.xml | 1 + includes/PHPExcel/Examples/GnumericReader.php | 60 +++ .../PHPExcel/Examples/GnumericTest.gnumeric | Bin 0 -> 7823 bytes includes/PHPExcel/Examples/OOCalcReader.php | 61 +++ .../PHPExcel/Examples/OOCalcReaderPCLZip.php | 64 +++ includes/PHPExcel/Examples/OOCalcTest.ods | Bin 0 -> 17931 bytes includes/PHPExcel/Examples/Quadratic.php | 68 +++ includes/PHPExcel/Examples/Quadratic.xlsx | Bin 0 -> 8908 bytes includes/PHPExcel/Examples/Quadratic2.php | 65 +++ includes/PHPExcel/Examples/SylkReader.php | 50 ++ includes/PHPExcel/Examples/SylkTest.slk | 152 ++++++ includes/PHPExcel/Examples/XMLReader.php | 60 +++ includes/PHPExcel/Examples/XMLTest.xml | 450 ++++++++++++++++++ includes/PHPExcel/Examples/runall.php | 130 +++++ 90 files changed, 11066 insertions(+) create mode 100644 includes/PHPExcel/Examples/.gitignore create mode 100644 includes/PHPExcel/Examples/01pharSimple.php create mode 100644 includes/PHPExcel/Examples/01simple-download-ods.php create mode 100644 includes/PHPExcel/Examples/01simple-download-pdf.php create mode 100644 includes/PHPExcel/Examples/01simple-download-xls.php create mode 100644 includes/PHPExcel/Examples/01simple-download-xlsx.php create mode 100644 includes/PHPExcel/Examples/01simple.php create mode 100644 includes/PHPExcel/Examples/01simplePCLZip.php create mode 100644 includes/PHPExcel/Examples/02types-xls.php create mode 100644 includes/PHPExcel/Examples/02types.php create mode 100644 includes/PHPExcel/Examples/03formulas.php create mode 100644 includes/PHPExcel/Examples/04printing.php create mode 100644 includes/PHPExcel/Examples/05featuredemo.inc.php create mode 100644 includes/PHPExcel/Examples/05featuredemo.php create mode 100644 includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite.php create mode 100644 includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite3.php create mode 100644 includes/PHPExcel/Examples/06largescale-with-cellcaching.php create mode 100644 includes/PHPExcel/Examples/06largescale-xls.php create mode 100644 includes/PHPExcel/Examples/06largescale.php create mode 100644 includes/PHPExcel/Examples/07reader.php create mode 100644 includes/PHPExcel/Examples/07readerPCLZip.php create mode 100644 includes/PHPExcel/Examples/08conditionalformatting.php create mode 100644 includes/PHPExcel/Examples/08conditionalformatting2.php create mode 100644 includes/PHPExcel/Examples/09pagebreaks.php create mode 100644 includes/PHPExcel/Examples/10autofilter-selection-1.php create mode 100644 includes/PHPExcel/Examples/10autofilter-selection-2.php create mode 100644 includes/PHPExcel/Examples/10autofilter-selection-display.php create mode 100644 includes/PHPExcel/Examples/10autofilter.php create mode 100644 includes/PHPExcel/Examples/11documentsecurity-xls.php create mode 100644 includes/PHPExcel/Examples/11documentsecurity.php create mode 100644 includes/PHPExcel/Examples/12cellProtection.php create mode 100644 includes/PHPExcel/Examples/13calculation.php create mode 100644 includes/PHPExcel/Examples/14excel5.php create mode 100644 includes/PHPExcel/Examples/15datavalidation-xls.php create mode 100644 includes/PHPExcel/Examples/15datavalidation.php create mode 100644 includes/PHPExcel/Examples/16csv.php create mode 100644 includes/PHPExcel/Examples/17html.php create mode 100644 includes/PHPExcel/Examples/18extendedcalculation.php create mode 100644 includes/PHPExcel/Examples/19namedrange.php create mode 100644 includes/PHPExcel/Examples/20readexcel5.php create mode 100644 includes/PHPExcel/Examples/21pdf.php create mode 100644 includes/PHPExcel/Examples/22heavilyformatted.php create mode 100644 includes/PHPExcel/Examples/23sharedstyles.php create mode 100644 includes/PHPExcel/Examples/24readfilter.php create mode 100644 includes/PHPExcel/Examples/25inmemoryimage.php create mode 100644 includes/PHPExcel/Examples/26utf8.php create mode 100644 includes/PHPExcel/Examples/27imagesexcel5.php create mode 100644 includes/PHPExcel/Examples/28iterator.php create mode 100644 includes/PHPExcel/Examples/29advancedvaluebinder.php create mode 100644 includes/PHPExcel/Examples/30template.php create mode 100644 includes/PHPExcel/Examples/31docproperties_write-xls.php create mode 100644 includes/PHPExcel/Examples/31docproperties_write.php create mode 100644 includes/PHPExcel/Examples/32chartreadwrite.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-area.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-bar-stacked.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-bar.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-column-2.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-column.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-composite.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-line.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-multiple-charts.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-pie.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-radar.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-scatter.php create mode 100644 includes/PHPExcel/Examples/33chartcreate-stock.php create mode 100644 includes/PHPExcel/Examples/34chartupdate.php create mode 100644 includes/PHPExcel/Examples/35chartrender.php create mode 100644 includes/PHPExcel/Examples/36chartreadwriteHTML.php create mode 100644 includes/PHPExcel/Examples/36chartreadwritePDF.php create mode 100644 includes/PHPExcel/Examples/37page_layout_view.php create mode 100644 includes/PHPExcel/Examples/38cloneWorksheet.php create mode 100644 includes/PHPExcel/Examples/39dropdown.php create mode 100644 includes/PHPExcel/Examples/40duplicateStyle.php create mode 100644 includes/PHPExcel/Examples/41password.php create mode 100644 includes/PHPExcel/Examples/42richText.php create mode 100644 includes/PHPExcel/Examples/Excel2003XMLReader.php create mode 100644 includes/PHPExcel/Examples/Excel2003XMLTest.xml create mode 100644 includes/PHPExcel/Examples/GnumericReader.php create mode 100644 includes/PHPExcel/Examples/GnumericTest.gnumeric create mode 100644 includes/PHPExcel/Examples/OOCalcReader.php create mode 100644 includes/PHPExcel/Examples/OOCalcReaderPCLZip.php create mode 100644 includes/PHPExcel/Examples/OOCalcTest.ods create mode 100644 includes/PHPExcel/Examples/Quadratic.php create mode 100644 includes/PHPExcel/Examples/Quadratic.xlsx create mode 100644 includes/PHPExcel/Examples/Quadratic2.php create mode 100644 includes/PHPExcel/Examples/SylkReader.php create mode 100644 includes/PHPExcel/Examples/SylkTest.slk create mode 100644 includes/PHPExcel/Examples/XMLReader.php create mode 100644 includes/PHPExcel/Examples/XMLTest.xml create mode 100644 includes/PHPExcel/Examples/runall.php diff --git a/includes/PHPExcel/Examples/.gitignore b/includes/PHPExcel/Examples/.gitignore new file mode 100644 index 0000000..1888a98 --- /dev/null +++ b/includes/PHPExcel/Examples/.gitignore @@ -0,0 +1,3 @@ + +*.xls +*.xlsx \ No newline at end of file diff --git a/includes/PHPExcel/Examples/01pharSimple.php b/includes/PHPExcel/Examples/01pharSimple.php new file mode 100644 index 0000000..a880477 --- /dev/null +++ b/includes/PHPExcel/Examples/01pharSimple.php @@ -0,0 +1,112 @@ +'); + +/** Include PHPExcel */ +require_once '../Build/PHPExcel.phar'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("office PHPExcel php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel5 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/01simple-download-ods.php b/includes/PHPExcel/Examples/01simple-download-ods.php new file mode 100644 index 0000000..574fb01 --- /dev/null +++ b/includes/PHPExcel/Examples/01simple-download-ods.php @@ -0,0 +1,89 @@ +getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + +// Rename worksheet +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Redirect output to a client’s web browser (OpenDocument) +header('Content-Type: application/vnd.oasis.opendocument.spreadsheet'); +header('Content-Disposition: attachment;filename="01simple.ods"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified +header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header ('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'OpenDocument'); +$objWriter->save('php://output'); +exit; diff --git a/includes/PHPExcel/Examples/01simple-download-pdf.php b/includes/PHPExcel/Examples/01simple-download-pdf.php new file mode 100644 index 0000000..287b0e8 --- /dev/null +++ b/includes/PHPExcel/Examples/01simple-download-pdf.php @@ -0,0 +1,104 @@ +getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PDF Test Document") + ->setSubject("PDF Test Document") + ->setDescription("Test document for PDF, generated using PHP classes.") + ->setKeywords("pdf php") + ->setCategory("Test result file"); + + +// Add some data +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + +// Rename worksheet +$objPHPExcel->getActiveSheet()->setTitle('Simple'); +$objPHPExcel->getActiveSheet()->setShowGridLines(false); + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +if (!PHPExcel_Settings::setPdfRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + '
' . + 'at the top of this script as appropriate for your directory structure' + ); +} + + +// Redirect output to a client’s web browser (PDF) +header('Content-Type: application/pdf'); +header('Content-Disposition: attachment;filename="01simple.pdf"'); +header('Cache-Control: max-age=0'); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); +$objWriter->save('php://output'); +exit; diff --git a/includes/PHPExcel/Examples/01simple-download-xls.php b/includes/PHPExcel/Examples/01simple-download-xls.php new file mode 100644 index 0000000..60fc901 --- /dev/null +++ b/includes/PHPExcel/Examples/01simple-download-xls.php @@ -0,0 +1,89 @@ +getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + +// Rename worksheet +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Redirect output to a client’s web browser (Excel5) +header('Content-Type: application/vnd.ms-excel'); +header('Content-Disposition: attachment;filename="01simple.xls"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified +header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header ('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save('php://output'); +exit; diff --git a/includes/PHPExcel/Examples/01simple-download-xlsx.php b/includes/PHPExcel/Examples/01simple-download-xlsx.php new file mode 100644 index 0000000..538888e --- /dev/null +++ b/includes/PHPExcel/Examples/01simple-download-xlsx.php @@ -0,0 +1,89 @@ +getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + +// Rename worksheet +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Redirect output to a client’s web browser (Excel2007) +header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); +header('Content-Disposition: attachment;filename="01simple.xlsx"'); +header('Cache-Control: max-age=0'); +// If you're serving to IE 9, then the following may be needed +header('Cache-Control: max-age=1'); + +// If you're serving to IE over SSL, then the following may be needed +header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past +header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified +header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 +header ('Pragma: public'); // HTTP/1.0 + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save('php://output'); +exit; diff --git a/includes/PHPExcel/Examples/01simple.php b/includes/PHPExcel/Examples/01simple.php new file mode 100644 index 0000000..965fefa --- /dev/null +++ b/includes/PHPExcel/Examples/01simple.php @@ -0,0 +1,118 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("office PHPExcel php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + + +$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); +$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); +$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true); + + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/01simplePCLZip.php b/includes/PHPExcel/Examples/01simplePCLZip.php new file mode 100644 index 0000000..0b7a46c --- /dev/null +++ b/includes/PHPExcel/Examples/01simplePCLZip.php @@ -0,0 +1,106 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("office PHPExcel php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + + +$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); +$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); +$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true); + + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +// Use PCLZip rather than ZipArchive to create the Excel2007 OfficeOpenXML file +PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/02types-xls.php b/includes/PHPExcel/Examples/02types-xls.php new file mode 100644 index 0000000..cc1dc37 --- /dev/null +++ b/includes/PHPExcel/Examples/02types-xls.php @@ -0,0 +1,183 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + +// Set default font +echo date('H:i:s') , " Set default font" , EOL; +$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial') + ->setSize(10); + +// Add some data, resembling some different data types +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String') + ->setCellValue('B1', 'Simple') + ->setCellValue('C1', 'PHPExcel'); + +$objPHPExcel->getActiveSheet()->setCellValue('A2', 'String') + ->setCellValue('B2', 'Symbols') + ->setCellValue('C2', '!+&=()~§±æþ'); + +$objPHPExcel->getActiveSheet()->setCellValue('A3', 'String') + ->setCellValue('B3', 'UTF-8') + ->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов'); + +$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number') + ->setCellValue('B4', 'Integer') + ->setCellValue('C4', 12); + +$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number') + ->setCellValue('B5', 'Float') + ->setCellValue('C5', 34.56); + +$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number') + ->setCellValue('B6', 'Negative') + ->setCellValue('C6', -7.89); + +$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean') + ->setCellValue('B7', 'True') + ->setCellValue('C7', true); + +$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean') + ->setCellValue('B8', 'False') + ->setCellValue('C8', false); + +$dateTimeNow = time(); +$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time') + ->setCellValue('B9', 'Date') + ->setCellValue('C9', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); +$objPHPExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); + +$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Date/Time') + ->setCellValue('B10', 'Time') + ->setCellValue('C10', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); +$objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4); + +$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Date/Time') + ->setCellValue('B11', 'Date and Time') + ->setCellValue('C11', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); +$objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME); + +$objPHPExcel->getActiveSheet()->setCellValue('A12', 'NULL') + ->setCellValue('C12', NULL); + +$objRichText = new PHPExcel_RichText(); +$objRichText->createText('你好 '); +$objPayable = $objRichText->createTextRun('你 好 吗?'); +$objPayable->getFont()->setBold(true); +$objPayable->getFont()->setItalic(true); +$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) ); + +$objRichText->createText(', unless specified otherwise on the invoice.'); + +$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text') + ->setCellValue('C13', $objRichText); + + +$objRichText2 = new PHPExcel_RichText(); +$objRichText2->createText("black text\n"); + +$objRed = $objRichText2->createTextRun("red text"); +$objRed->getFont()->setColor( new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED ) ); + +$objPHPExcel->getActiveSheet()->getCell("C14")->setValue($objRichText2); +$objPHPExcel->getActiveSheet()->getStyle("C14")->getAlignment()->setWrapText(true); + + +$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Datatypes'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Reload workbook from saved file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcel = PHPExcel_IOFactory::load(str_replace('.php', '.xls', __FILE__)); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +var_dump($objPHPExcel->getActiveSheet()->toArray()); + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done testing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/02types.php b/includes/PHPExcel/Examples/02types.php new file mode 100644 index 0000000..ff5421e --- /dev/null +++ b/includes/PHPExcel/Examples/02types.php @@ -0,0 +1,183 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + +// Set default font +echo date('H:i:s') , " Set default font" , EOL; +$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial') + ->setSize(10); + +// Add some data, resembling some different data types +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String') + ->setCellValue('B1', 'Simple') + ->setCellValue('C1', 'PHPExcel'); + +$objPHPExcel->getActiveSheet()->setCellValue('A2', 'String') + ->setCellValue('B2', 'Symbols') + ->setCellValue('C2', '!+&=()~§±æþ'); + +$objPHPExcel->getActiveSheet()->setCellValue('A3', 'String') + ->setCellValue('B3', 'UTF-8') + ->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов'); + +$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number') + ->setCellValue('B4', 'Integer') + ->setCellValue('C4', 12); + +$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number') + ->setCellValue('B5', 'Float') + ->setCellValue('C5', 34.56); + +$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number') + ->setCellValue('B6', 'Negative') + ->setCellValue('C6', -7.89); + +$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean') + ->setCellValue('B7', 'True') + ->setCellValue('C7', true); + +$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean') + ->setCellValue('B8', 'False') + ->setCellValue('C8', false); + +$dateTimeNow = time(); +$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time') + ->setCellValue('B9', 'Date') + ->setCellValue('C9', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); +$objPHPExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); + +$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Date/Time') + ->setCellValue('B10', 'Time') + ->setCellValue('C10', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); +$objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4); + +$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Date/Time') + ->setCellValue('B11', 'Date and Time') + ->setCellValue('C11', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow )); +$objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME); + +$objPHPExcel->getActiveSheet()->setCellValue('A12', 'NULL') + ->setCellValue('C12', NULL); + +$objRichText = new PHPExcel_RichText(); +$objRichText->createText('你好 '); + +$objPayable = $objRichText->createTextRun('你 好 吗?'); +$objPayable->getFont()->setBold(true); +$objPayable->getFont()->setItalic(true); +$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) ); + +$objRichText->createText(', unless specified otherwise on the invoice.'); + +$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text') + ->setCellValue('C13', $objRichText); + + +$objRichText2 = new PHPExcel_RichText(); +$objRichText2->createText("black text\n"); + +$objRed = $objRichText2->createTextRun("red text"); +$objRed->getFont()->setColor( new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED ) ); + +$objPHPExcel->getActiveSheet()->getCell("C14")->setValue($objRichText2); +$objPHPExcel->getActiveSheet()->getStyle("C14")->getAlignment()->setWrapText(true); + + +$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Datatypes'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Reload workbook from saved file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcel = PHPExcel_IOFactory::load(str_replace('.php', '.xlsx', __FILE__)); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +var_dump($objPHPExcel->getActiveSheet()->toArray()); + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done testing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/03formulas.php b/includes/PHPExcel/Examples/03formulas.php new file mode 100644 index 0000000..1396717 --- /dev/null +++ b/includes/PHPExcel/Examples/03formulas.php @@ -0,0 +1,149 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data, we will use some formulas here +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Sum:'); + +$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range #1') + ->setCellValue('B2', 3) + ->setCellValue('B3', 7) + ->setCellValue('B4', 13) + ->setCellValue('B5', '=SUM(B2:B4)'); +echo date('H:i:s') , " Sum of Range #1 is " , + $objPHPExcel->getActiveSheet()->getCell('B5')->getCalculatedValue() , EOL; + +$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range #2') + ->setCellValue('C2', 5) + ->setCellValue('C3', 11) + ->setCellValue('C4', 17) + ->setCellValue('C5', '=SUM(C2:C4)'); +echo date('H:i:s') , " Sum of Range #2 is " , + $objPHPExcel->getActiveSheet()->getCell('C5')->getCalculatedValue() , EOL; + +$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Total of both ranges:'); +$objPHPExcel->getActiveSheet()->setCellValue('B7', '=SUM(B5:C5)'); +echo date('H:i:s') , " Sum of both Ranges is " , + $objPHPExcel->getActiveSheet()->getCell('B7')->getCalculatedValue() , EOL; + +$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Minimum of both ranges:'); +$objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C4)'); +echo date('H:i:s') , " Minimum value in either Range is " , + $objPHPExcel->getActiveSheet()->getCell('B8')->getCalculatedValue() , EOL; + +$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Maximum of both ranges:'); +$objPHPExcel->getActiveSheet()->setCellValue('B9', '=MAX(B2:C4)'); +echo date('H:i:s') , " Maximum value in either Range is " , + $objPHPExcel->getActiveSheet()->getCell('B9')->getCalculatedValue() , EOL; + +$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Average of both ranges:'); +$objPHPExcel->getActiveSheet()->setCellValue('B10', '=AVERAGE(B2:C4)'); +echo date('H:i:s') , " Average value of both Ranges is " , + $objPHPExcel->getActiveSheet()->getCell('B10')->getCalculatedValue() , EOL; + + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Formulas'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + +// +// If we set Pre Calculated Formulas to true then PHPExcel will calculate all formulae in the +// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae +// using functions or features (such as array formulae) that aren't yet supported by the calculation engine +// If the value is false (the default) for the Excel2007 Writer, then MS Excel (or the application used to +// open the file) will need to recalculate values itself to guarantee that the correct results are available. +// +//$objWriter->setPreCalculateFormulas(true); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/04printing.php b/includes/PHPExcel/Examples/04printing.php new file mode 100644 index 0000000..14358b0 --- /dev/null +++ b/includes/PHPExcel/Examples/04printing.php @@ -0,0 +1,125 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data, we will use printing features +echo date('H:i:s') , " Add some data" , EOL; +for ($i = 1; $i < 200; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $i); + $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, 'Test value'); +} + +// Set header and footer. When no different headers for odd/even are used, odd header is assumed. +echo date('H:i:s') , " Set header/footer" , EOL; +$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HPlease treat this document as confidential!'); +$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N'); + +// Add a drawing to the header +echo date('H:i:s') , " Add a drawing to the header" , EOL; +$objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing(); +$objDrawing->setName('PHPExcel logo'); +$objDrawing->setPath('./images/phpexcel_logo.gif'); +$objDrawing->setHeight(36); +$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT); + +// Set page orientation and size +echo date('H:i:s') , " Set page orientation and size" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); +$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Printing'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/05featuredemo.inc.php b/includes/PHPExcel/Examples/05featuredemo.inc.php new file mode 100644 index 0000000..b543ca4 --- /dev/null +++ b/includes/PHPExcel/Examples/05featuredemo.inc.php @@ -0,0 +1,394 @@ +getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet, representing sales data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Invoice'); +$objPHPExcel->getActiveSheet()->setCellValue('D1', PHPExcel_Shared_Date::PHPToExcel( gmmktime(0,0,0,date('m'),date('d'),date('Y')) )); +$objPHPExcel->getActiveSheet()->getStyle('D1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15); +$objPHPExcel->getActiveSheet()->setCellValue('E1', '#12566'); + +$objPHPExcel->getActiveSheet()->setCellValue('A3', 'Product Id'); +$objPHPExcel->getActiveSheet()->setCellValue('B3', 'Description'); +$objPHPExcel->getActiveSheet()->setCellValue('C3', 'Price'); +$objPHPExcel->getActiveSheet()->setCellValue('D3', 'Amount'); +$objPHPExcel->getActiveSheet()->setCellValue('E3', 'Total'); + +$objPHPExcel->getActiveSheet()->setCellValue('A4', '1001'); +$objPHPExcel->getActiveSheet()->setCellValue('B4', 'PHP for dummies'); +$objPHPExcel->getActiveSheet()->setCellValue('C4', '20'); +$objPHPExcel->getActiveSheet()->setCellValue('D4', '1'); +$objPHPExcel->getActiveSheet()->setCellValue('E4', '=IF(D4<>"",C4*D4,"")'); + +$objPHPExcel->getActiveSheet()->setCellValue('A5', '1012'); +$objPHPExcel->getActiveSheet()->setCellValue('B5', 'OpenXML for dummies'); +$objPHPExcel->getActiveSheet()->setCellValue('C5', '22'); +$objPHPExcel->getActiveSheet()->setCellValue('D5', '2'); +$objPHPExcel->getActiveSheet()->setCellValue('E5', '=IF(D5<>"",C5*D5,"")'); + +$objPHPExcel->getActiveSheet()->setCellValue('E6', '=IF(D6<>"",C6*D6,"")'); +$objPHPExcel->getActiveSheet()->setCellValue('E7', '=IF(D7<>"",C7*D7,"")'); +$objPHPExcel->getActiveSheet()->setCellValue('E8', '=IF(D8<>"",C8*D8,"")'); +$objPHPExcel->getActiveSheet()->setCellValue('E9', '=IF(D9<>"",C9*D9,"")'); + +$objPHPExcel->getActiveSheet()->setCellValue('D11', 'Total excl.:'); +$objPHPExcel->getActiveSheet()->setCellValue('E11', '=SUM(E4:E9)'); + +$objPHPExcel->getActiveSheet()->setCellValue('D12', 'VAT:'); +$objPHPExcel->getActiveSheet()->setCellValue('E12', '=E11*0.21'); + +$objPHPExcel->getActiveSheet()->setCellValue('D13', 'Total incl.:'); +$objPHPExcel->getActiveSheet()->setCellValue('E13', '=E11+E12'); + +// Add comment +echo date('H:i:s') , " Add comments" , EOL; + +$objPHPExcel->getActiveSheet()->getComment('E11')->setAuthor('PHPExcel'); +$objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun('PHPExcel:'); +$objCommentRichText->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun("\r\n"); +$objPHPExcel->getActiveSheet()->getComment('E11')->getText()->createTextRun('Total amount on the current invoice, excluding VAT.'); + +$objPHPExcel->getActiveSheet()->getComment('E12')->setAuthor('PHPExcel'); +$objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun('PHPExcel:'); +$objCommentRichText->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun("\r\n"); +$objPHPExcel->getActiveSheet()->getComment('E12')->getText()->createTextRun('Total amount of VAT on the current invoice.'); + +$objPHPExcel->getActiveSheet()->getComment('E13')->setAuthor('PHPExcel'); +$objCommentRichText = $objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun('PHPExcel:'); +$objCommentRichText->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun("\r\n"); +$objPHPExcel->getActiveSheet()->getComment('E13')->getText()->createTextRun('Total amount on the current invoice, including VAT.'); +$objPHPExcel->getActiveSheet()->getComment('E13')->setWidth('100pt'); +$objPHPExcel->getActiveSheet()->getComment('E13')->setHeight('100pt'); +$objPHPExcel->getActiveSheet()->getComment('E13')->setMarginLeft('150pt'); +$objPHPExcel->getActiveSheet()->getComment('E13')->getFillColor()->setRGB('EEEEEE'); + + +// Add rich-text string +echo date('H:i:s') , " Add rich-text string" , EOL; +$objRichText = new PHPExcel_RichText(); +$objRichText->createText('This invoice is '); + +$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month'); +$objPayable->getFont()->setBold(true); +$objPayable->getFont()->setItalic(true); +$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) ); + +$objRichText->createText(', unless specified otherwise on the invoice.'); + +$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText); + +// Merge cells +echo date('H:i:s') , " Merge cells" , EOL; +$objPHPExcel->getActiveSheet()->mergeCells('A18:E22'); +$objPHPExcel->getActiveSheet()->mergeCells('A28:B28'); // Just to test... +$objPHPExcel->getActiveSheet()->unmergeCells('A28:B28'); // Just to test... + +// Protect cells +echo date('H:i:s') , " Protect cells" , EOL; +$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); // Needs to be set to true in order to enable any worksheet protection! +$objPHPExcel->getActiveSheet()->protectCells('A3:E13', 'PHPExcel'); + +// Set cell number formats +echo date('H:i:s') , " Set cell number formats" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('E4:E13')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); + +// Set column widths +echo date('H:i:s') , " Set column widths" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12); +$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(12); + +// Set fonts +echo date('H:i:s') , " Set fonts" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setName('Candara'); +$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(20); +$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); +$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); + +$objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); +$objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE); + +$objPHPExcel->getActiveSheet()->getStyle('D13')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('E13')->getFont()->setBold(true); + +// Set alignments +echo date('H:i:s') , " Set alignments" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('D11')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); +$objPHPExcel->getActiveSheet()->getStyle('D12')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); +$objPHPExcel->getActiveSheet()->getStyle('D13')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); + +$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY); +$objPHPExcel->getActiveSheet()->getStyle('A18')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); + +$objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setShrinkToFit(true); + +// Set thin black border outline around column +echo date('H:i:s') , " Set thin black border outline around column" , EOL; +$styleThinBlackBorderOutline = array( + 'borders' => array( + 'outline' => array( + 'style' => PHPExcel_Style_Border::BORDER_THIN, + 'color' => array('argb' => 'FF000000'), + ), + ), +); +$objPHPExcel->getActiveSheet()->getStyle('A4:E10')->applyFromArray($styleThinBlackBorderOutline); + + +// Set thick brown border outline around "Total" +echo date('H:i:s') , " Set thick brown border outline around Total" , EOL; +$styleThickBrownBorderOutline = array( + 'borders' => array( + 'outline' => array( + 'style' => PHPExcel_Style_Border::BORDER_THICK, + 'color' => array('argb' => 'FF993300'), + ), + ), +); +$objPHPExcel->getActiveSheet()->getStyle('D13:E13')->applyFromArray($styleThickBrownBorderOutline); + +// Set fills +echo date('H:i:s') , " Set fills" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1:E1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID); +$objPHPExcel->getActiveSheet()->getStyle('A1:E1')->getFill()->getStartColor()->setARGB('FF808080'); + +// Set style for header row using alternative method +echo date('H:i:s') , " Set style for header row using alternative method" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('A3:E3')->applyFromArray( + array( + 'font' => array( + 'bold' => true + ), + 'alignment' => array( + 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT, + ), + 'borders' => array( + 'top' => array( + 'style' => PHPExcel_Style_Border::BORDER_THIN + ) + ), + 'fill' => array( + 'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR, + 'rotation' => 90, + 'startcolor' => array( + 'argb' => 'FFA0A0A0' + ), + 'endcolor' => array( + 'argb' => 'FFFFFFFF' + ) + ) + ) +); + +$objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray( + array( + 'alignment' => array( + 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT, + ), + 'borders' => array( + 'left' => array( + 'style' => PHPExcel_Style_Border::BORDER_THIN + ) + ) + ) +); + +$objPHPExcel->getActiveSheet()->getStyle('B3')->applyFromArray( + array( + 'alignment' => array( + 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT, + ) + ) +); + +$objPHPExcel->getActiveSheet()->getStyle('E3')->applyFromArray( + array( + 'borders' => array( + 'right' => array( + 'style' => PHPExcel_Style_Border::BORDER_THIN + ) + ) + ) +); + +// Unprotect a cell +echo date('H:i:s') , " Unprotect a cell" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('B1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED); + +// Add a hyperlink to the sheet +echo date('H:i:s') , " Add a hyperlink to an external website" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('E26', 'www.phpexcel.net'); +$objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setUrl('http://www.phpexcel.net'); +$objPHPExcel->getActiveSheet()->getCell('E26')->getHyperlink()->setTooltip('Navigate to website'); +$objPHPExcel->getActiveSheet()->getStyle('E26')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); + +echo date('H:i:s') , " Add a hyperlink to another cell on a different worksheet within the workbook" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('E27', 'Terms and conditions'); +$objPHPExcel->getActiveSheet()->getCell('E27')->getHyperlink()->setUrl("sheet://'Terms and conditions'!A1"); +$objPHPExcel->getActiveSheet()->getCell('E27')->getHyperlink()->setTooltip('Review terms and conditions'); +$objPHPExcel->getActiveSheet()->getStyle('E27')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT); + +// Add a drawing to the worksheet +echo date('H:i:s') , " Add a drawing to the worksheet" , EOL; +$objDrawing = new PHPExcel_Worksheet_Drawing(); +$objDrawing->setName('Logo'); +$objDrawing->setDescription('Logo'); +$objDrawing->setPath('./images/officelogo.jpg'); +$objDrawing->setHeight(36); +$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); + +// Add a drawing to the worksheet +echo date('H:i:s') , " Add a drawing to the worksheet" , EOL; +$objDrawing = new PHPExcel_Worksheet_Drawing(); +$objDrawing->setName('Paid'); +$objDrawing->setDescription('Paid'); +$objDrawing->setPath('./images/paid.png'); +$objDrawing->setCoordinates('B15'); +$objDrawing->setOffsetX(110); +$objDrawing->setRotation(25); +$objDrawing->getShadow()->setVisible(true); +$objDrawing->getShadow()->setDirection(45); +$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); + +// Add a drawing to the worksheet +echo date('H:i:s') , " Add a drawing to the worksheet" , EOL; +$objDrawing = new PHPExcel_Worksheet_Drawing(); +$objDrawing->setName('PHPExcel logo'); +$objDrawing->setDescription('PHPExcel logo'); +$objDrawing->setPath('./images/phpexcel_logo.gif'); +$objDrawing->setHeight(36); +$objDrawing->setCoordinates('D24'); +$objDrawing->setOffsetX(10); +$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); + +// Play around with inserting and removing rows and columns +echo date('H:i:s') , " Play around with inserting and removing rows and columns" , EOL; +$objPHPExcel->getActiveSheet()->insertNewRowBefore(6, 10); +$objPHPExcel->getActiveSheet()->removeRow(6, 10); +$objPHPExcel->getActiveSheet()->insertNewColumnBefore('E', 5); +$objPHPExcel->getActiveSheet()->removeColumn('E', 5); + +// Set header and footer. When no different headers for odd/even are used, odd header is assumed. +echo date('H:i:s') , " Set header/footer" , EOL; +$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&BInvoice&RPrinted on &D'); +$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N'); + +// Set page orientation and size +echo date('H:i:s') , " Set page orientation and size" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT); +$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); + +// Rename first worksheet +echo date('H:i:s') , " Rename first worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Invoice'); + + +// Create a new worksheet, after the default sheet +echo date('H:i:s') , " Create a second Worksheet object" , EOL; +$objPHPExcel->createSheet(); + +// Llorem ipsum... +$sLloremIpsum = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus eget ante. Sed cursus nunc semper tortor. Aliquam luctus purus non elit. Fusce vel elit commodo sapien dignissim dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur accumsan magna sed massa. Nullam bibendum quam ac ipsum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin augue. Praesent malesuada justo sed orci. Pellentesque lacus ligula, sodales quis, ultricies a, ultricies vitae, elit. Sed luctus consectetuer dolor. Vivamus vel sem ut nisi sodales accumsan. Nunc et felis. Suspendisse semper viverra odio. Morbi at odio. Integer a orci a purus venenatis molestie. Nam mattis. Praesent rhoncus, nisi vel mattis auctor, neque nisi faucibus sem, non dapibus elit pede ac nisl. Cras turpis.'; + +// Add some data to the second sheet, resembling some different data types +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(1); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Terms and conditions'); +$objPHPExcel->getActiveSheet()->setCellValue('A3', $sLloremIpsum); +$objPHPExcel->getActiveSheet()->setCellValue('A4', $sLloremIpsum); +$objPHPExcel->getActiveSheet()->setCellValue('A5', $sLloremIpsum); +$objPHPExcel->getActiveSheet()->setCellValue('A6', $sLloremIpsum); + +// Set the worksheet tab color +echo date('H:i:s') , " Set the worksheet tab color" , EOL; +$objPHPExcel->getActiveSheet()->getTabColor()->setARGB('FF0094FF');; + +// Set alignments +echo date('H:i:s') , " Set alignments" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('A3:A6')->getAlignment()->setWrapText(true); + +// Set column widths +echo date('H:i:s') , " Set column widths" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(80); + +// Set fonts +echo date('H:i:s') , " Set fonts" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('Candara'); +$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20); +$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); + +$objPHPExcel->getActiveSheet()->getStyle('A3:A6')->getFont()->setSize(8); + +// Add a drawing to the worksheet +echo date('H:i:s') , " Add a drawing to the worksheet" , EOL; +$objDrawing = new PHPExcel_Worksheet_Drawing(); +$objDrawing->setName('Terms and conditions'); +$objDrawing->setDescription('Terms and conditions'); +$objDrawing->setPath('./images/termsconditions.jpg'); +$objDrawing->setCoordinates('B14'); +$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); + +// Set page orientation and size +echo date('H:i:s') , " Set page orientation and size" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); +$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); + +// Rename second worksheet +echo date('H:i:s') , " Rename second worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Terms and conditions'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); diff --git a/includes/PHPExcel/Examples/05featuredemo.php b/includes/PHPExcel/Examples/05featuredemo.php new file mode 100644 index 0000000..66d4980 --- /dev/null +++ b/includes/PHPExcel/Examples/05featuredemo.php @@ -0,0 +1,78 @@ +'); + +date_default_timezone_set('Europe/London'); + +include "05featuredemo.inc.php"; + +/** Include PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite.php b/includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite.php new file mode 100644 index 0000000..cbdb59b --- /dev/null +++ b/includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite.php @@ -0,0 +1,129 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite; +if (PHPExcel_Settings::setCacheStorageMethod($cacheMethod)) { + echo date('H:i:s') , " Enable Cell Caching using " , $cacheMethod , " method" , EOL; +} else { + echo date('H:i:s') , " Unable to set Cell Caching using " , $cacheMethod , " method, reverting to memory" , EOL; +} + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname"); +$objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname"); +$objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone"); +$objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax"); +$objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?"); + + +// Hide "Phone" and "fax" column +echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false); + + +// Set outline levels +echo date('H:i:s') , " Set outline levels" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1) + ->setVisible(false) + ->setCollapsed(true); + +// Freeze panes +echo date('H:i:s') , " Freeze panes" , EOL; +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + +// Rows to repeat at top +echo date('H:i:s') , " Rows to repeat at top" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1); + + +// Add data +for ($i = 2; $i <= 5000; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i") + ->setCellValue('B' . $i, "LName $i") + ->setCellValue('C' . $i, "PhoneNo $i") + ->setCellValue('D' . $i, "FaxNo $i") + ->setCellValue('E' . $i, true); +} + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite3.php b/includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite3.php new file mode 100644 index 0000000..ca04f85 --- /dev/null +++ b/includes/PHPExcel/Examples/06largescale-with-cellcaching-sqlite3.php @@ -0,0 +1,129 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3; +if (PHPExcel_Settings::setCacheStorageMethod($cacheMethod)) { + echo date('H:i:s') , " Enable Cell Caching using " , $cacheMethod , " method" , EOL; +} else { + echo date('H:i:s') , " Unable to set Cell Caching using " , $cacheMethod , " method, reverting to memory" , EOL; +} + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname"); +$objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname"); +$objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone"); +$objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax"); +$objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?"); + + +// Hide "Phone" and "fax" column +echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false); + + +// Set outline levels +echo date('H:i:s') , " Set outline levels" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1) + ->setVisible(false) + ->setCollapsed(true); + +// Freeze panes +echo date('H:i:s') , " Freeze panes" , EOL; +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + +// Rows to repeat at top +echo date('H:i:s') , " Rows to repeat at top" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1); + + +// Add data +for ($i = 2; $i <= 5000; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i") + ->setCellValue('B' . $i, "LName $i") + ->setCellValue('C' . $i, "PhoneNo $i") + ->setCellValue('D' . $i, "FaxNo $i") + ->setCellValue('E' . $i, true); +} + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/06largescale-with-cellcaching.php b/includes/PHPExcel/Examples/06largescale-with-cellcaching.php new file mode 100644 index 0000000..aa23b8c --- /dev/null +++ b/includes/PHPExcel/Examples/06largescale-with-cellcaching.php @@ -0,0 +1,128 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip; +if (!PHPExcel_Settings::setCacheStorageMethod($cacheMethod)) { + die($cacheMethod . " caching method is not available" . EOL); +} +echo date('H:i:s') , " Enable Cell Caching using " , $cacheMethod , " method" , EOL; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname"); +$objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname"); +$objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone"); +$objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax"); +$objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?"); + + +// Hide "Phone" and "fax" column +echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false); + + +// Set outline levels +echo date('H:i:s') , " Set outline levels" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1) + ->setVisible(false) + ->setCollapsed(true); + +// Freeze panes +echo date('H:i:s') , " Freeze panes" , EOL; +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + +// Rows to repeat at top +echo date('H:i:s') , " Rows to repeat at top" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1); + + +// Add data +for ($i = 2; $i <= 5000; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i") + ->setCellValue('B' . $i, "LName $i") + ->setCellValue('C' . $i, "PhoneNo $i") + ->setCellValue('D' . $i, "FaxNo $i") + ->setCellValue('E' . $i, true); +} + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/06largescale-xls.php b/includes/PHPExcel/Examples/06largescale-xls.php new file mode 100644 index 0000000..00137ad --- /dev/null +++ b/includes/PHPExcel/Examples/06largescale-xls.php @@ -0,0 +1,136 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +/* +After doing some test, I've got these results benchmarked +for writing to Excel2007: + + Number of rows Seconds to generate + 200 3 + 500 4 + 1000 6 + 2000 12 + 4000 36 + 8000 64 + 15000 465 +*/ + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname"); +$objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname"); +$objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone"); +$objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax"); +$objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?"); + + +// Hide "Phone" and "fax" column +echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false); + + +// Set outline levels +echo date('H:i:s') , " Set outline levels" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1) + ->setVisible(false) + ->setCollapsed(true); + +// Freeze panes +echo date('H:i:s') , " Freeze panes" , EOL; +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + +// Rows to repeat at top +echo date('H:i:s') , " Rows to repeat at top" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1); + + +// Add data +for ($i = 2; $i <= 5000; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i") + ->setCellValue('B' . $i, "LName $i") + ->setCellValue('C' . $i, "PhoneNo $i") + ->setCellValue('D' . $i, "FaxNo $i") + ->setCellValue('E' . $i, true); +} + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/06largescale.php b/includes/PHPExcel/Examples/06largescale.php new file mode 100644 index 0000000..b0fa440 --- /dev/null +++ b/includes/PHPExcel/Examples/06largescale.php @@ -0,0 +1,136 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +/* +After doing some test, I've got these results benchmarked +for writing to Excel2007: + + Number of rows Seconds to generate + 200 3 + 500 4 + 1000 6 + 2000 12 + 4000 36 + 8000 64 + 15000 465 +*/ + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname"); +$objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname"); +$objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone"); +$objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax"); +$objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?"); + + +// Hide "Phone" and "fax" column +echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false); + + +// Set outline levels +echo date('H:i:s') , " Set outline levels" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1) + ->setVisible(false) + ->setCollapsed(true); + +// Freeze panes +echo date('H:i:s') , " Freeze panes" , EOL; +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + +// Rows to repeat at top +echo date('H:i:s') , " Rows to repeat at top" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1); + + +// Add data +for ($i = 2; $i <= 5000; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i") + ->setCellValue('B' . $i, "LName $i") + ->setCellValue('C' . $i, "PhoneNo $i") + ->setCellValue('D' . $i, "FaxNo $i") + ->setCellValue('E' . $i, true); +} + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/07reader.php b/includes/PHPExcel/Examples/07reader.php new file mode 100644 index 0000000..616b662 --- /dev/null +++ b/includes/PHPExcel/Examples/07reader.php @@ -0,0 +1,76 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +if (!file_exists("05featuredemo.xlsx")) { + exit("Please run 05featuredemo.php first." . EOL); +} + +echo date('H:i:s') , " Load from Excel2007 file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcel = PHPExcel_IOFactory::load("05featuredemo.xlsx"); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/07readerPCLZip.php b/includes/PHPExcel/Examples/07readerPCLZip.php new file mode 100644 index 0000000..90e8590 --- /dev/null +++ b/includes/PHPExcel/Examples/07readerPCLZip.php @@ -0,0 +1,79 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +if (!file_exists("05featuredemo.xlsx")) { + exit("Please run 05featuredemo.php first." . EOL); +} + +// Use PCLZip rather than ZipArchive to read the Excel2007 OfficeOpenXML file +PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); + +echo date('H:i:s') , " Load from Excel2007 file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcel = PHPExcel_IOFactory::load("05featuredemo.xlsx"); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/08conditionalformatting.php b/includes/PHPExcel/Examples/08conditionalformatting.php new file mode 100644 index 0000000..f65ec9e --- /dev/null +++ b/includes/PHPExcel/Examples/08conditionalformatting.php @@ -0,0 +1,189 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet, representing sales data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Description') + ->setCellValue('B1', 'Amount'); + +$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Paycheck received') + ->setCellValue('B2', 100); + +$objPHPExcel->getActiveSheet()->setCellValue('A3', 'Cup of coffee bought') + ->setCellValue('B3', -1.5); + +$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Cup of coffee bought') + ->setCellValue('B4', -1.5); + +$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Cup of tea bought') + ->setCellValue('B5', -1.2); + +$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Found some money') + ->setCellValue('B6', 8); + +$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Total:') + ->setCellValue('B7', '=SUM(B2:B6)'); + + +// Set column widths +echo date('H:i:s') , " Set column widths" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30); +$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(12); + + +// Add conditional formatting +echo date('H:i:s') , " Add conditional formatting" , EOL; +$objConditional1 = new PHPExcel_Style_Conditional(); +$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_BETWEEN) + ->addCondition('200') + ->addCondition('400'); +$objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_YELLOW); +$objConditional1->getStyle()->getFont()->setBold(true); +$objConditional1->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); + +$objConditional2 = new PHPExcel_Style_Conditional(); +$objConditional2->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN) + ->addCondition('0'); +$objConditional2->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED); +$objConditional2->getStyle()->getFont()->setItalic(true); +$objConditional2->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); + +$objConditional3 = new PHPExcel_Style_Conditional(); +$objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL) + ->addCondition('0'); +$objConditional3->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN); +$objConditional3->getStyle()->getFont()->setItalic(true); +$objConditional3->getStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); + +$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles(); +array_push($conditionalStyles, $objConditional1); +array_push($conditionalStyles, $objConditional2); +array_push($conditionalStyles, $objConditional3); +$objPHPExcel->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles); + + +// duplicate the conditional styles across a range of cells +echo date('H:i:s') , " Duplicate the conditional formatting across a range of cells" , EOL; +$objPHPExcel->getActiveSheet()->duplicateConditionalStyle( + $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles(), + 'B3:B7' + ); + + +// Set fonts +echo date('H:i:s') , " Set fonts" , EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true); +//$objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('A7:B7')->getFont()->setBold(true); +//$objPHPExcel->getActiveSheet()->getStyle('B7')->getFont()->setBold(true); + + +// Set header and footer. When no different headers for odd/even are used, odd header is assumed. +echo date('H:i:s') , " Set header/footer" , EOL; +$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&BPersonal cash register&RPrinted on &D'); +$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N'); + + +// Set page orientation and size +echo date('H:i:s') , " Set page orientation and size" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT); +$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); + + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Invoice'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Save Excel5 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/08conditionalformatting2.php b/includes/PHPExcel/Examples/08conditionalformatting2.php new file mode 100644 index 0000000..bbe084a --- /dev/null +++ b/includes/PHPExcel/Examples/08conditionalformatting2.php @@ -0,0 +1,136 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet, representing sales data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet() + ->setCellValue('A1', '-0.5') + ->setCellValue('A2', '-0.25') + ->setCellValue('A3', '0.0') + ->setCellValue('A4', '0.25') + ->setCellValue('A5', '0.5') + ->setCellValue('A6', '0.75') + ->setCellValue('A7', '1.0') + ->setCellValue('A8', '1.25') +; + +$objPHPExcel->getActiveSheet()->getStyle('A1:A8') + ->getNumberFormat() + ->setFormatCode( + PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00 + ); + + +// Add conditional formatting +echo date('H:i:s') , " Add conditional formatting" , EOL; +$objConditional1 = new PHPExcel_Style_Conditional(); +$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_LESSTHAN) + ->addCondition('0'); +$objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED); + +$objConditional3 = new PHPExcel_Style_Conditional(); +$objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS) + ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL) + ->addCondition('1'); +$objConditional3->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN); + +$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('A1')->getConditionalStyles(); +array_push($conditionalStyles, $objConditional1); +array_push($conditionalStyles, $objConditional3); +$objPHPExcel->getActiveSheet()->getStyle('A1')->setConditionalStyles($conditionalStyles); + + +// duplicate the conditional styles across a range of cells +echo date('H:i:s') , " Duplicate the conditional formatting across a range of cells" , EOL; +$objPHPExcel->getActiveSheet()->duplicateConditionalStyle( + $objPHPExcel->getActiveSheet()->getStyle('A1')->getConditionalStyles(), + 'A2:A8' + ); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Save Excel5 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/09pagebreaks.php b/includes/PHPExcel/Examples/09pagebreaks.php new file mode 100644 index 0000000..6b8c185 --- /dev/null +++ b/includes/PHPExcel/Examples/09pagebreaks.php @@ -0,0 +1,134 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data and page breaks" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname") + ->setCellValue('B1', "Lastname") + ->setCellValue('C1', "Phone") + ->setCellValue('D1', "Fax") + ->setCellValue('E1', "Is Client ?"); + + +// Add data +for ($i = 2; $i <= 50; $i++) { + $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i"); + $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, "LName $i"); + $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, "PhoneNo $i"); + $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, "FaxNo $i"); + $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, true); + + // Add page breaks every 10 rows + if ($i % 10 == 0) { + // Add a page break + $objPHPExcel->getActiveSheet()->setBreak( 'A' . $i, PHPExcel_Worksheet::BREAK_ROW ); + } +} + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setTitle('Printing Options'); + +// Set print headers +$objPHPExcel->getActiveSheet() + ->getHeaderFooter()->setOddHeader('&C&24&K0000FF&B&U&A'); +$objPHPExcel->getActiveSheet() + ->getHeaderFooter()->setEvenHeader('&C&24&K0000FF&B&U&A'); + +// Set print footers +$objPHPExcel->getActiveSheet() + ->getHeaderFooter()->setOddFooter('&R&D &T&C&F&LPage &P / &N'); +$objPHPExcel->getActiveSheet() + ->getHeaderFooter()->setEvenFooter('&L&D &T&C&F&RPage &P / &N'); + + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/10autofilter-selection-1.php b/includes/PHPExcel/Examples/10autofilter-selection-1.php new file mode 100644 index 0000000..7542a52 --- /dev/null +++ b/includes/PHPExcel/Examples/10autofilter-selection-1.php @@ -0,0 +1,221 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s').' Create new PHPExcel object'.EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s').' Set document properties'.EOL; +$objPHPExcel->getProperties()->setCreator('Maarten Balliauw') + ->setLastModifiedBy('Maarten Balliauw') + ->setTitle('PHPExcel Test Document') + ->setSubject('PHPExcel Test Document') + ->setDescription('Test document for PHPExcel, generated using PHP classes.') + ->setKeywords('office PHPExcel php') + ->setCategory('Test result file'); + +// Create the worksheet +echo date('H:i:s').' Add data'.EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Financial Year') + ->setCellValue('B1', 'Financial Period') + ->setCellValue('C1', 'Country') + ->setCellValue('D1', 'Date') + ->setCellValue('E1', 'Sales Value') + ->setCellValue('F1', 'Expenditure') + ; +$startYear = $endYear = $currentYear = date('Y'); +$startYear--; +$endYear++; + +$years = range($startYear,$endYear); +$periods = range(1,12); +$countries = array( 'United States', 'UK', 'France', 'Germany', + 'Italy', 'Spain', 'Portugal', 'Japan' + ); + +$row = 2; +foreach($years as $year) { + foreach($periods as $period) { + foreach($countries as $country) { + $endDays = date('t',mktime(0,0,0,$period,1,$year)); + for($i = 1; $i <= $endDays; ++$i) { + $eDate = PHPExcel_Shared_Date::FormattedPHPToExcel( + $year, + $period, + $i + ); + $value = rand(500,1000) * (1 + rand(-0.25,+0.25)); + $salesValue = $invoiceValue = NULL; + $incomeOrExpenditure = rand(-1,1); + if ($incomeOrExpenditure == -1) { + $expenditure = rand(-500,-1000) * (1 + rand(-0.25,+0.25)); + $income = NULL; + } elseif ($incomeOrExpenditure == 1) { + $expenditure = rand(-500,-1000) * (1 + rand(-0.25,+0.25)); + $income = rand(500,1000) * (1 + rand(-0.25,+0.25));; + } else { + $expenditure = NULL; + $income = rand(500,1000) * (1 + rand(-0.25,+0.25));; + } + $dataArray = array( $year, + $period, + $country, + $eDate, + $income, + $expenditure, + ); + $objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A'.$row++); + } + } + } +} +$row--; + + +// Set styling +echo date('H:i:s').' Set styling'.EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(TRUE); +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); +$objPHPExcel->getActiveSheet()->getStyle('D2:D'.$row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); +$objPHPExcel->getActiveSheet()->getStyle('E2:F'.$row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); +$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(14); +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + + +// Set autofilter range +echo date('H:i:s').' Set autofilter range'.EOL; +// Always include the complete filter range! +// Excel does support setting only the caption +// row, but that's not a best practise... +$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension()); + +// Set active filters +$autoFilter = $objPHPExcel->getActiveSheet()->getAutoFilter(); +echo date('H:i:s').' Set active filters'.EOL; +// Filter the Country column on a filter value of countries beginning with the letter U (or Japan) +// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter +$autoFilter->getColumn('C') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + 'u*' + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); +$autoFilter->getColumn('C') + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + 'japan' + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); +// Filter the Date column on a filter value of the first day of every period of the current year +// We us a dateGroup ruletype for this, although it is still a standard filter +foreach($periods as $period) { + $endDate = date('t',mktime(0,0,0,$period,1,$currentYear)); + + $autoFilter->getColumn('D') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + array( + 'year' => $currentYear, + 'month' => $period, + 'day' => $endDate + ) + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP); +} +// Display only sales values that are blank +// Standard filter, operator equals, and value of NULL +$autoFilter->getColumn('E') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + '' + ); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s').' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB'.EOL; + +// Echo done +echo date('H:i:s').' Done writing files'.EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/10autofilter-selection-2.php b/includes/PHPExcel/Examples/10autofilter-selection-2.php new file mode 100644 index 0000000..c89173f --- /dev/null +++ b/includes/PHPExcel/Examples/10autofilter-selection-2.php @@ -0,0 +1,213 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s').' Create new PHPExcel object'.EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s').' Set document properties'.EOL; +$objPHPExcel->getProperties()->setCreator('Maarten Balliauw') + ->setLastModifiedBy('Maarten Balliauw') + ->setTitle('PHPExcel Test Document') + ->setSubject('PHPExcel Test Document') + ->setDescription('Test document for PHPExcel, generated using PHP classes.') + ->setKeywords('office PHPExcel php') + ->setCategory('Test result file'); + +// Create the worksheet +echo date('H:i:s').' Add data'.EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Financial Year') + ->setCellValue('B1', 'Financial Period') + ->setCellValue('C1', 'Country') + ->setCellValue('D1', 'Date') + ->setCellValue('E1', 'Sales Value') + ->setCellValue('F1', 'Expenditure') + ; +$startYear = $endYear = $currentYear = date('Y'); +$startYear--; +$endYear++; + +$years = range($startYear,$endYear); +$periods = range(1,12); +$countries = array( 'United States', 'UK', 'France', 'Germany', + 'Italy', 'Spain', 'Portugal', 'Japan' + ); + +$row = 2; +foreach($years as $year) { + foreach($periods as $period) { + foreach($countries as $country) { + $endDays = date('t',mktime(0,0,0,$period,1,$year)); + for($i = 1; $i <= $endDays; ++$i) { + $eDate = PHPExcel_Shared_Date::FormattedPHPToExcel( + $year, + $period, + $i + ); + $value = rand(500,1000) * (1 + rand(-0.25,+0.25)); + $salesValue = $invoiceValue = NULL; + $incomeOrExpenditure = rand(-1,1); + if ($incomeOrExpenditure == -1) { + $expenditure = rand(-500,-1000) * (1 + rand(-0.25,+0.25)); + $income = NULL; + } elseif ($incomeOrExpenditure == 1) { + $expenditure = rand(-500,-1000) * (1 + rand(-0.25,+0.25)); + $income = rand(500,1000) * (1 + rand(-0.25,+0.25));; + } else { + $expenditure = NULL; + $income = rand(500,1000) * (1 + rand(-0.25,+0.25));; + } + $dataArray = array( $year, + $period, + $country, + $eDate, + $income, + $expenditure, + ); + $objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A'.$row++); + } + } + } +} +$row--; + + +// Set styling +echo date('H:i:s').' Set styling'.EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(TRUE); +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); +$objPHPExcel->getActiveSheet()->getStyle('D2:D'.$row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); +$objPHPExcel->getActiveSheet()->getStyle('E2:F'.$row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); +$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(14); +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + + +// Set autofilter range +echo date('H:i:s').' Set autofilter range'.EOL; +// Always include the complete filter range! +// Excel does support setting only the caption +// row, but that's not a best practise... +$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension()); + +// Set active filters +$autoFilter = $objPHPExcel->getActiveSheet()->getAutoFilter(); +echo date('H:i:s').' Set active filters'.EOL; +// Filter the Country column on a filter value of Germany +// As it's just a simple value filter, we can use FILTERTYPE_FILTER +$autoFilter->getColumn('C') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + 'Germany' + ); +// Filter the Date column on a filter value of the year to date +$autoFilter->getColumn('D') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + NULL, + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER); +// Display only sales values that are between 400 and 600 +$autoFilter->getColumn('E') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL, + 400 + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); +$autoFilter->getColumn('E') + ->setJoin(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL, + 600 + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s').' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB'.EOL; + +// Echo done +echo date('H:i:s').' Done writing files'.EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/10autofilter-selection-display.php b/includes/PHPExcel/Examples/10autofilter-selection-display.php new file mode 100644 index 0000000..cf2b8ac --- /dev/null +++ b/includes/PHPExcel/Examples/10autofilter-selection-display.php @@ -0,0 +1,198 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s').' Create new PHPExcel object'.EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s').' Set document properties'.EOL; +$objPHPExcel->getProperties()->setCreator('Maarten Balliauw') + ->setLastModifiedBy('Maarten Balliauw') + ->setTitle('PHPExcel Test Document') + ->setSubject('PHPExcel Test Document') + ->setDescription('Test document for PHPExcel, generated using PHP classes.') + ->setKeywords('office PHPExcel php') + ->setCategory('Test result file'); + +// Create the worksheet +echo date('H:i:s').' Add data'.EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Financial Year') + ->setCellValue('B1', 'Financial Period') + ->setCellValue('C1', 'Country') + ->setCellValue('D1', 'Date') + ->setCellValue('E1', 'Sales Value') + ->setCellValue('F1', 'Expenditure') + ; +$startYear = $endYear = $currentYear = date('Y'); +$startYear--; +$endYear++; + +$years = range($startYear,$endYear); +$periods = range(1,12); +$countries = array( 'United States', 'UK', 'France', 'Germany', + 'Italy', 'Spain', 'Portugal', 'Japan' + ); + +$row = 2; +foreach($years as $year) { + foreach($periods as $period) { + foreach($countries as $country) { + $endDays = date('t',mktime(0,0,0,$period,1,$year)); + for($i = 1; $i <= $endDays; ++$i) { + $eDate = PHPExcel_Shared_Date::FormattedPHPToExcel( + $year, + $period, + $i + ); + $value = rand(500,1000) * (1 + rand(-0.25,+0.25)); + $salesValue = $invoiceValue = NULL; + $incomeOrExpenditure = rand(-1,1); + if ($incomeOrExpenditure == -1) { + $expenditure = rand(-500,-1000) * (1 + rand(-0.25,+0.25)); + $income = NULL; + } elseif ($incomeOrExpenditure == 1) { + $expenditure = rand(-500,-1000) * (1 + rand(-0.25,+0.25)); + $income = rand(500,1000) * (1 + rand(-0.25,+0.25));; + } else { + $expenditure = NULL; + $income = rand(500,1000) * (1 + rand(-0.25,+0.25));; + } + $dataArray = array( $year, + $period, + $country, + $eDate, + $income, + $expenditure, + ); + $objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A'.$row++); + } + } + } +} +$row--; + + +// Set styling +echo date('H:i:s').' Set styling'.EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true); +$objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(TRUE); +$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); +$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); +$objPHPExcel->getActiveSheet()->getStyle('D2:D'.$row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); +$objPHPExcel->getActiveSheet()->getStyle('E2:F'.$row)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); +$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(14); +$objPHPExcel->getActiveSheet()->freezePane('A2'); + + + +// Set autofilter range +echo date('H:i:s').' Set autofilter range'.EOL; +// Always include the complete filter range! +// Excel does support setting only the caption +// row, but that's not a best practise... +$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension()); + +// Set active filters +$autoFilter = $objPHPExcel->getActiveSheet()->getAutoFilter(); +echo date('H:i:s').' Set active filters'.EOL; +// Filter the Country column on a filter value of countries beginning with the letter U (or Japan) +// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter +$autoFilter->getColumn('C') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + 'u*' + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); +$autoFilter->getColumn('C') + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + 'japan' + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); +// Filter the Date column on a filter value of the first day of every period of the current year +// We us a dateGroup ruletype for this, although it is still a standard filter +foreach($periods as $period) { + $endDate = date('t',mktime(0,0,0,$period,1,$currentYear)); + + $autoFilter->getColumn('D') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + array( + 'year' => $currentYear, + 'month' => $period, + 'day' => $endDate + ) + ) + ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP); +} +// Display only sales values that are blank +// Standard filter, operator equals, and value of NULL +$autoFilter->getColumn('E') + ->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER) + ->createRule() + ->setRule( + PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL, + '' + ); + +// Execute filtering +echo date('H:i:s').' Execute filtering'.EOL; +$autoFilter->showHideRows(); + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Display Results of filtering +echo date('H:i:s').' Display filtered rows'.EOL; +foreach ($objPHPExcel->getActiveSheet()->getRowIterator() as $row) { + if ($objPHPExcel->getActiveSheet()->getRowDimension($row->getRowIndex())->getVisible()) { + echo ' Row number - ' , $row->getRowIndex() , ' '; + echo $objPHPExcel->getActiveSheet()->getCell('C'.$row->getRowIndex())->getValue(), ' '; + echo $objPHPExcel->getActiveSheet()->getCell('D'.$row->getRowIndex())->getFormattedValue(), ' '; + echo EOL; + } +} diff --git a/includes/PHPExcel/Examples/10autofilter.php b/includes/PHPExcel/Examples/10autofilter.php new file mode 100644 index 0000000..ea3f763 --- /dev/null +++ b/includes/PHPExcel/Examples/10autofilter.php @@ -0,0 +1,171 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +// Create new PHPExcel object +echo date('H:i:s').' Create new PHPExcel object'.EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s').' Set document properties'.EOL; +$objPHPExcel->getProperties()->setCreator('Maarten Balliauw') + ->setLastModifiedBy('Maarten Balliauw') + ->setTitle('PHPExcel Test Document') + ->setSubject('PHPExcel Test Document') + ->setDescription('Test document for PHPExcel, generated using PHP classes.') + ->setKeywords('office PHPExcel php') + ->setCategory('Test result file'); + +// Create the worksheet +echo date('H:i:s').' Add data'.EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Year') + ->setCellValue('B1', 'Quarter') + ->setCellValue('C1', 'Country') + ->setCellValue('D1', 'Sales'); + +$dataArray = array(array('2010', 'Q1', 'United States', 790), + array('2010', 'Q2', 'United States', 730), + array('2010', 'Q3', 'United States', 860), + array('2010', 'Q4', 'United States', 850), + array('2011', 'Q1', 'United States', 800), + array('2011', 'Q2', 'United States', 700), + array('2011', 'Q3', 'United States', 900), + array('2011', 'Q4', 'United States', 950), + array('2010', 'Q1', 'Belgium', 380), + array('2010', 'Q2', 'Belgium', 390), + array('2010', 'Q3', 'Belgium', 420), + array('2010', 'Q4', 'Belgium', 460), + array('2011', 'Q1', 'Belgium', 400), + array('2011', 'Q2', 'Belgium', 350), + array('2011', 'Q3', 'Belgium', 450), + array('2011', 'Q4', 'Belgium', 500), + array('2010', 'Q1', 'UK', 690), + array('2010', 'Q2', 'UK', 610), + array('2010', 'Q3', 'UK', 620), + array('2010', 'Q4', 'UK', 600), + array('2011', 'Q1', 'UK', 720), + array('2011', 'Q2', 'UK', 650), + array('2011', 'Q3', 'UK', 580), + array('2011', 'Q4', 'UK', 510), + array('2010', 'Q1', 'France', 510), + array('2010', 'Q2', 'France', 490), + array('2010', 'Q3', 'France', 460), + array('2010', 'Q4', 'France', 590), + array('2011', 'Q1', 'France', 620), + array('2011', 'Q2', 'France', 650), + array('2011', 'Q3', 'France', 415), + array('2011', 'Q4', 'France', 570), + array('2010', 'Q1', 'Germany', 720), + array('2010', 'Q2', 'Germany', 680), + array('2010', 'Q3', 'Germany', 640), + array('2010', 'Q4', 'Germany', 660), + array('2011', 'Q1', 'Germany', 680), + array('2011', 'Q2', 'Germany', 620), + array('2011', 'Q3', 'Germany', 710), + array('2011', 'Q4', 'Germany', 690), + array('2010', 'Q1', 'Spain', 510), + array('2010', 'Q2', 'Spain', 490), + array('2010', 'Q3', 'Spain', 470), + array('2010', 'Q4', 'Spain', 420), + array('2011', 'Q1', 'Spain', 460), + array('2011', 'Q2', 'Spain', 390), + array('2011', 'Q3', 'Spain', 430), + array('2011', 'Q4', 'Spain', 415), + array('2010', 'Q1', 'Italy', 440), + array('2010', 'Q2', 'Italy', 410), + array('2010', 'Q3', 'Italy', 420), + array('2010', 'Q4', 'Italy', 450), + array('2011', 'Q1', 'Italy', 430), + array('2011', 'Q2', 'Italy', 370), + array('2011', 'Q3', 'Italy', 350), + array('2011', 'Q4', 'Italy', 335), + ); +$objPHPExcel->getActiveSheet()->fromArray($dataArray, NULL, 'A2'); + +// Set title row bold +echo date('H:i:s').' Set title row bold'.EOL; +$objPHPExcel->getActiveSheet()->getStyle('A1:D1')->getFont()->setBold(true); + +// Set autofilter +echo date('H:i:s').' Set autofilter'.EOL; +// Always include the complete filter range! +// Excel does support setting only the caption +// row, but that's not a best practise... +$objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension()); + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s').' Peak memory usage: '.(memory_get_peak_usage(true) / 1024 / 1024).' MB'.EOL; + +// Echo done +echo date('H:i:s').' Done writing files'.EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/11documentsecurity-xls.php b/includes/PHPExcel/Examples/11documentsecurity-xls.php new file mode 100644 index 0000000..b104c7b --- /dev/null +++ b/includes/PHPExcel/Examples/11documentsecurity-xls.php @@ -0,0 +1,109 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello'); +$objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!'); +$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello'); +$objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!'); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set document security +echo date('H:i:s') , " Set document security" , EOL; +$objPHPExcel->getSecurity()->setLockWindows(true); +$objPHPExcel->getSecurity()->setLockStructure(true); +$objPHPExcel->getSecurity()->setWorkbookPassword("PHPExcel"); + + +// Set sheet security +echo date('H:i:s') , " Set sheet security" , EOL; +$objPHPExcel->getActiveSheet()->getProtection()->setPassword('PHPExcel'); +$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); // This should be enabled in order to enable any of the following! +$objPHPExcel->getActiveSheet()->getProtection()->setSort(true); +$objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true); +$objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/11documentsecurity.php b/includes/PHPExcel/Examples/11documentsecurity.php new file mode 100644 index 0000000..96f5d99 --- /dev/null +++ b/includes/PHPExcel/Examples/11documentsecurity.php @@ -0,0 +1,109 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello'); +$objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!'); +$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello'); +$objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!'); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set document security +echo date('H:i:s') , " Set document security" , EOL; +$objPHPExcel->getSecurity()->setLockWindows(true); +$objPHPExcel->getSecurity()->setLockStructure(true); +$objPHPExcel->getSecurity()->setWorkbookPassword("PHPExcel"); + + +// Set sheet security +echo date('H:i:s') , " Set sheet security" , EOL; +$objPHPExcel->getActiveSheet()->getProtection()->setPassword('PHPExcel'); +$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); // This should be enabled in order to enable any of the following! +$objPHPExcel->getActiveSheet()->getProtection()->setSort(true); +$objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true); +$objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/12cellProtection.php b/includes/PHPExcel/Examples/12cellProtection.php new file mode 100644 index 0000000..77bfee4 --- /dev/null +++ b/includes/PHPExcel/Examples/12cellProtection.php @@ -0,0 +1,107 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Mark Baker") + ->setLastModifiedBy("Mark Baker") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Crouching'); +$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Tiger'); +$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Hidden'); +$objPHPExcel->getActiveSheet()->setCellValue('B2', 'Dragon'); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set document security +echo date('H:i:s') , " Set cell protection" , EOL; + + +// Set sheet security +echo date('H:i:s') , " Set sheet security" , EOL; +$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); +$objPHPExcel->getActiveSheet() + ->getStyle('A2:B2') + ->getProtection()->setLocked( + PHPExcel_Style_Protection::PROTECTION_UNPROTECTED + ); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/13calculation.php b/includes/PHPExcel/Examples/13calculation.php new file mode 100644 index 0000000..01e63ea --- /dev/null +++ b/includes/PHPExcel/Examples/13calculation.php @@ -0,0 +1,235 @@ +'); + +date_default_timezone_set('Europe/London'); +mt_srand(1234567890); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// List functions +echo date('H:i:s') , " List implemented functions" , EOL; +$objCalc = PHPExcel_Calculation::getInstance(); +print_r($objCalc->listFunctionNames()); + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Add some data, we will use some formulas here +echo date('H:i:s') , " Add some data and formulas" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Count:') + ->setCellValue('A15', 'Sum:') + ->setCellValue('A16', 'Max:') + ->setCellValue('A17', 'Min:') + ->setCellValue('A18', 'Average:') + ->setCellValue('A19', 'Median:') + ->setCellValue('A20', 'Mode:'); + +$objPHPExcel->getActiveSheet()->setCellValue('A22', 'CountA:') + ->setCellValue('A23', 'MaxA:') + ->setCellValue('A24', 'MinA:'); + +$objPHPExcel->getActiveSheet()->setCellValue('A26', 'StDev:') + ->setCellValue('A27', 'StDevA:') + ->setCellValue('A28', 'StDevP:') + ->setCellValue('A29', 'StDevPA:'); + +$objPHPExcel->getActiveSheet()->setCellValue('A31', 'DevSq:') + ->setCellValue('A32', 'Var:') + ->setCellValue('A33', 'VarA:') + ->setCellValue('A34', 'VarP:') + ->setCellValue('A35', 'VarPA:'); + +$objPHPExcel->getActiveSheet()->setCellValue('A37', 'Date:'); + + +$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range 1') + ->setCellValue('B2', 2) + ->setCellValue('B3', 8) + ->setCellValue('B4', 10) + ->setCellValue('B5', True) + ->setCellValue('B6', False) + ->setCellValue('B7', 'Text String') + ->setCellValue('B9', '22') + ->setCellValue('B10', 4) + ->setCellValue('B11', 6) + ->setCellValue('B12', 12); + +$objPHPExcel->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)') + ->setCellValue('B15', '=SUM(B2:B12)') + ->setCellValue('B16', '=MAX(B2:B12)') + ->setCellValue('B17', '=MIN(B2:B12)') + ->setCellValue('B18', '=AVERAGE(B2:B12)') + ->setCellValue('B19', '=MEDIAN(B2:B12)') + ->setCellValue('B20', '=MODE(B2:B12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)') + ->setCellValue('B23', '=MAXA(B2:B12)') + ->setCellValue('B24', '=MINA(B2:B12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)') + ->setCellValue('B27', '=STDEVA(B2:B12)') + ->setCellValue('B28', '=STDEVP(B2:B12)') + ->setCellValue('B29', '=STDEVPA(B2:B12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)') + ->setCellValue('B32', '=VAR(B2:B12)') + ->setCellValue('B33', '=VARA(B2:B12)') + ->setCellValue('B34', '=VARP(B2:B12)') + ->setCellValue('B35', '=VARPA(B2:B12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)') + ->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )') + ->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")') + ->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )') + ->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )'); + + +$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range 2') + ->setCellValue('C2', 1) + ->setCellValue('C3', 2) + ->setCellValue('C4', 2) + ->setCellValue('C5', 3) + ->setCellValue('C6', 3) + ->setCellValue('C7', 3) + ->setCellValue('C8', '0') + ->setCellValue('C9', 4) + ->setCellValue('C10', 4) + ->setCellValue('C11', 4) + ->setCellValue('C12', 4); + +$objPHPExcel->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)') + ->setCellValue('C15', '=SUM(C2:C12)') + ->setCellValue('C16', '=MAX(C2:C12)') + ->setCellValue('C17', '=MIN(C2:C12)') + ->setCellValue('C18', '=AVERAGE(C2:C12)') + ->setCellValue('C19', '=MEDIAN(C2:C12)') + ->setCellValue('C20', '=MODE(C2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)') + ->setCellValue('C23', '=MAXA(C2:C12)') + ->setCellValue('C24', '=MINA(C2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)') + ->setCellValue('C27', '=STDEVA(C2:C12)') + ->setCellValue('C28', '=STDEVP(C2:C12)') + ->setCellValue('C29', '=STDEVPA(C2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)') + ->setCellValue('C32', '=VAR(C2:C12)') + ->setCellValue('C33', '=VARA(C2:C12)') + ->setCellValue('C34', '=VARP(C2:C12)') + ->setCellValue('C35', '=VARPA(C2:C12)'); + + +$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Range 3') + ->setCellValue('D2', 2) + ->setCellValue('D3', 3) + ->setCellValue('D4', 4); + +$objPHPExcel->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"'); + +$objPHPExcel->getActiveSheet()->setCellValue('E12', 'Other functions') + ->setCellValue('E14', '=PI()') + ->setCellValue('E15', '=RAND()') + ->setCellValue('E16', '=RANDBETWEEN(5, 10)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E17', 'Count of both ranges:') + ->setCellValue('F17', '=COUNT(B2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E18', 'Total of both ranges:') + ->setCellValue('F18', '=SUM(B2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:') + ->setCellValue('F19', '=MAX(B2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:') + ->setCellValue('F20', '=MIN(B2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E21', 'Average of both ranges:') + ->setCellValue('F21', '=AVERAGE(B2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E22', 'Median of both ranges:') + ->setCellValue('F22', '=MEDIAN(B2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:') + ->setCellValue('F23', '=MODE(B2:C12)'); + + +// Calculated data +echo date('H:i:s') , " Calculated data" , EOL; +for ($col = 'B'; $col != 'G'; ++$col) { + for($row = 14; $row <= 41; ++$row) { + if ((!is_null($formula = $objPHPExcel->getActiveSheet()->getCell($col.$row)->getValue())) && + ($formula[0] == '=')) { + echo 'Value of ' , $col , $row , ' [' , $formula , ']: ' , + $objPHPExcel->getActiveSheet()->getCell($col.$row)->getCalculatedValue() . EOL; + } + } +} + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + +// +// If we set Pre Calculated Formulas to true then PHPExcel will calculate all formulae in the +// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae +// using functions or features (such as array formulae) that aren't yet supported by the calculation engine +// If the value is false (the default) for the Excel2007 Writer, then MS Excel (or the application used to +// open the file) will need to recalculate values itself to guarantee that the correct results are available. +// +//$objWriter->setPreCalculateFormulas(true); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/14excel5.php b/includes/PHPExcel/Examples/14excel5.php new file mode 100644 index 0000000..3fd3d69 --- /dev/null +++ b/includes/PHPExcel/Examples/14excel5.php @@ -0,0 +1,63 @@ +'); + +date_default_timezone_set('Europe/London'); + +include "05featuredemo.inc.php"; + +/** PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/15datavalidation-xls.php b/includes/PHPExcel/Examples/15datavalidation-xls.php new file mode 100644 index 0000000..2f8fa5e --- /dev/null +++ b/includes/PHPExcel/Examples/15datavalidation-xls.php @@ -0,0 +1,142 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...") + ->setCellValue('A3', "Number:") + ->setCellValue('B3', "10") + ->setCellValue('A5', "List:") + ->setCellValue('B5', "Item A") + ->setCellValue('A7', "List #2:") + ->setCellValue('B7', "Item #2") + ->setCellValue('D2', "Item #1") + ->setCellValue('D3', "Item #2") + ->setCellValue('D4', "Item #3") + ->setCellValue('D5', "Item #4") + ->setCellValue('D6', "Item #5") + ; + + +// Set data validation +echo date('H:i:s') , " Set data validation" , EOL; +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP ); +$objValidation->setAllowBlank(true); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Only numbers between 10 and 20 are allowed!'); +$objValidation->setPromptTitle('Allowed input'); +$objValidation->setPrompt('Only numbers between 10 and 20 are allowed.'); +$objValidation->setFormula1(10); +$objValidation->setFormula2(20); + +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B5')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ); +$objValidation->setAllowBlank(false); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setShowDropDown(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Value is not in list.'); +$objValidation->setPromptTitle('Pick from list'); +$objValidation->setPrompt('Please pick a value from the drop-down list.'); +$objValidation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " !!! + +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B7')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ); +$objValidation->setAllowBlank(false); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setShowDropDown(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Value is not in list.'); +$objValidation->setPromptTitle('Pick from list'); +$objValidation->setPrompt('Please pick a value from the drop-down list.'); +$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!! + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/15datavalidation.php b/includes/PHPExcel/Examples/15datavalidation.php new file mode 100644 index 0000000..932bacc --- /dev/null +++ b/includes/PHPExcel/Examples/15datavalidation.php @@ -0,0 +1,143 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Create a first sheet +echo date('H:i:s') , " Add data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...") + ->setCellValue('A3', "Number:") + ->setCellValue('B3', "10") + ->setCellValue('A5', "List:") + ->setCellValue('B5', "Item A") + ->setCellValue('A7', "List #2:") + ->setCellValue('B7', "Item #2") + ->setCellValue('D2', "Item #1") + ->setCellValue('D3', "Item #2") + ->setCellValue('D4', "Item #3") + ->setCellValue('D5', "Item #4") + ->setCellValue('D6', "Item #5") + ; + + +// Set data validation +echo date('H:i:s') , " Set data validation" , EOL; +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP ); +$objValidation->setAllowBlank(true); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Only numbers between 10 and 20 are allowed!'); +$objValidation->setPromptTitle('Allowed input'); +$objValidation->setPrompt('Only numbers between 10 and 20 are allowed.'); +$objValidation->setFormula1(10); +$objValidation->setFormula2(20); + +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B5')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ); +$objValidation->setAllowBlank(false); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setShowDropDown(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Value is not in list.'); +$objValidation->setPromptTitle('Pick from list'); +$objValidation->setPrompt('Please pick a value from the drop-down list.'); +$objValidation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!! + + +$objValidation = $objPHPExcel->getActiveSheet()->getCell('B7')->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ); +$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ); +$objValidation->setAllowBlank(false); +$objValidation->setShowInputMessage(true); +$objValidation->setShowErrorMessage(true); +$objValidation->setShowDropDown(true); +$objValidation->setErrorTitle('Input error'); +$objValidation->setError('Value is not in list.'); +$objValidation->setPromptTitle('Pick from list'); +$objValidation->setPrompt('Please pick a value from the drop-down list.'); +$objValidation->setFormula1('$D$2:$D$6'); // Make sure NOT to put a range of cells or a formula between " and " !!! + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/16csv.php b/includes/PHPExcel/Examples/16csv.php new file mode 100644 index 0000000..71ebfd0 --- /dev/null +++ b/includes/PHPExcel/Examples/16csv.php @@ -0,0 +1,107 @@ +'); + +date_default_timezone_set('Europe/London'); + +include "05featuredemo.inc.php"; + +/** PHPExcel_IOFactory */ +require_once '../Classes/PHPExcel/IOFactory.php'; + + +echo date('H:i:s') , " Write to CSV format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter(',') + ->setEnclosure('"') + ->setLineEnding("\r\n") + ->setSheetIndex(0) + ->save(str_replace('.php', '.csv', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo date('H:i:s') , " File written to " , str_replace('.php', '.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Read from CSV format" , EOL; +$callStartTime = microtime(true); +$objReader = PHPExcel_IOFactory::createReader('CSV')->setDelimiter(',') + ->setEnclosure('"') + ->setLineEnding("\r\n") + ->setSheetIndex(0); +$objPHPExcelFromCSV = $objReader->load(str_replace('.php', '.csv', __FILE__)); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter2007 = PHPExcel_IOFactory::createWriter($objPHPExcelFromCSV, 'Excel2007'); +$objWriter2007->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Write to CSV format" , EOL; +$callStartTime = microtime(true); + +$objWriterCSV = PHPExcel_IOFactory::createWriter($objPHPExcelFromCSV, 'CSV'); +$objWriterCSV->setExcelCompatibility(true); +$objWriterCSV->save(str_replace('.php', '_excel.csv', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo date('H:i:s') , " File written to " , str_replace('.php', '_excel.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/17html.php b/includes/PHPExcel/Examples/17html.php new file mode 100644 index 0000000..0dc825b --- /dev/null +++ b/includes/PHPExcel/Examples/17html.php @@ -0,0 +1,64 @@ +'); + +date_default_timezone_set('Europe/London'); + +include "05featuredemo.inc.php"; + +/** PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +echo date('H:i:s') , " Write to HTML format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); +$objWriter->setSheetIndex(0); +//$objWriter->setImagesRoot('http://www.example.com'); +$objWriter->save(str_replace('.php', '.htm', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo date('H:i:s') , " File written to " , str_replace('.php', '.htm', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/18extendedcalculation.php b/includes/PHPExcel/Examples/18extendedcalculation.php new file mode 100644 index 0000000..3c6fcb4 --- /dev/null +++ b/includes/PHPExcel/Examples/18extendedcalculation.php @@ -0,0 +1,108 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// List functions +echo date('H:i:s') . " List implemented functions\n"; +$objCalc = PHPExcel_Calculation::getInstance(); +print_r($objCalc->listFunctionNames()); + +// Create new PHPExcel object +echo date('H:i:s') . " Create new PHPExcel object\n"; +$objPHPExcel = new PHPExcel(); + +// Add some data, we will use some formulas here +echo date('H:i:s') . " Add some data\n"; +$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Count:'); + +$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range 1'); +$objPHPExcel->getActiveSheet()->setCellValue('B2', 2); +$objPHPExcel->getActiveSheet()->setCellValue('B3', 8); +$objPHPExcel->getActiveSheet()->setCellValue('B4', 10); +$objPHPExcel->getActiveSheet()->setCellValue('B5', True); +$objPHPExcel->getActiveSheet()->setCellValue('B6', False); +$objPHPExcel->getActiveSheet()->setCellValue('B7', 'Text String'); +$objPHPExcel->getActiveSheet()->setCellValue('B9', '22'); +$objPHPExcel->getActiveSheet()->setCellValue('B10', 4); +$objPHPExcel->getActiveSheet()->setCellValue('B11', 6); +$objPHPExcel->getActiveSheet()->setCellValue('B12', 12); + +$objPHPExcel->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range 2'); +$objPHPExcel->getActiveSheet()->setCellValue('C2', 1); +$objPHPExcel->getActiveSheet()->setCellValue('C3', 2); +$objPHPExcel->getActiveSheet()->setCellValue('C4', 2); +$objPHPExcel->getActiveSheet()->setCellValue('C5', 3); +$objPHPExcel->getActiveSheet()->setCellValue('C6', 3); +$objPHPExcel->getActiveSheet()->setCellValue('C7', 3); +$objPHPExcel->getActiveSheet()->setCellValue('C8', '0'); +$objPHPExcel->getActiveSheet()->setCellValue('C9', 4); +$objPHPExcel->getActiveSheet()->setCellValue('C10', 4); +$objPHPExcel->getActiveSheet()->setCellValue('C11', 4); +$objPHPExcel->getActiveSheet()->setCellValue('C12', 4); + +$objPHPExcel->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)'); + +$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Range 3'); +$objPHPExcel->getActiveSheet()->setCellValue('D2', 2); +$objPHPExcel->getActiveSheet()->setCellValue('D3', 3); +$objPHPExcel->getActiveSheet()->setCellValue('D4', 4); + +$objPHPExcel->getActiveSheet()->setCellValue('D5', '=((D2 * D3) + D4) & " should be 10"'); + +$objPHPExcel->getActiveSheet()->setCellValue('E1', 'Other functions'); +$objPHPExcel->getActiveSheet()->setCellValue('E2', '=PI()'); +$objPHPExcel->getActiveSheet()->setCellValue('E3', '=RAND()'); +$objPHPExcel->getActiveSheet()->setCellValue('E4', '=RANDBETWEEN(5, 10)'); + +$objPHPExcel->getActiveSheet()->setCellValue('E14', 'Count of both ranges:'); +$objPHPExcel->getActiveSheet()->setCellValue('F14', '=COUNT(B2:C12)'); + +// Calculated data +echo date('H:i:s') . " Calculated data\n"; +echo 'Value of B14 [=COUNT(B2:B12)]: ' . $objPHPExcel->getActiveSheet()->getCell('B14')->getCalculatedValue() . "\r\n"; + + +// Echo memory peak usage +echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n"; + +// Echo done +echo date('H:i:s') . " Done" , EOL; diff --git a/includes/PHPExcel/Examples/19namedrange.php b/includes/PHPExcel/Examples/19namedrange.php new file mode 100644 index 0000000..acea22b --- /dev/null +++ b/includes/PHPExcel/Examples/19namedrange.php @@ -0,0 +1,129 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:') + ->setCellValue('A2', 'Lastname:') + ->setCellValue('A3', 'Fullname:') + ->setCellValue('B1', 'Maarten') + ->setCellValue('B2', 'Balliauw') + ->setCellValue('B3', '=B1 & " " & B2'); + +// Define named ranges +echo date('H:i:s') , " Define named ranges" , EOL; +$objPHPExcel->addNamedRange( new PHPExcel_NamedRange('PersonName', $objPHPExcel->getActiveSheet(), 'B1') ); +$objPHPExcel->addNamedRange( new PHPExcel_NamedRange('PersonLN', $objPHPExcel->getActiveSheet(), 'B2') ); + +// Rename named ranges +echo date('H:i:s') , " Rename named ranges" , EOL; +$objPHPExcel->getNamedRange('PersonName')->setName('PersonFN'); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Person'); + + +// Create a new worksheet, after the default sheet +echo date('H:i:s') , " Create new Worksheet object" , EOL; +$objPHPExcel->createSheet(); + +// Add some data to the second sheet, resembling some different data types +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(1); +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:') + ->setCellValue('A2', 'Lastname:') + ->setCellValue('A3', 'Fullname:') + ->setCellValue('B1', '=PersonFN') + ->setCellValue('B2', '=PersonLN') + ->setCellValue('B3', '=PersonFN & " " & PersonLN'); + +// Resolve range +echo date('H:i:s') , " Resolve range" , EOL; +echo 'Cell B1 {=PersonFN}: ' , $objPHPExcel->getActiveSheet()->getCell('B1')->getCalculatedValue() , EOL; +echo 'Cell B3 {=PersonFN & " " & PersonLN}: ' , $objPHPExcel->getActiveSheet()->getCell('B3')->getCalculatedValue() , EOL; +echo 'Cell Person!B1: ' , $objPHPExcel->getActiveSheet()->getCell('Person!B1')->getCalculatedValue() , EOL; + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Person (cloned)'); + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/20readexcel5.php b/includes/PHPExcel/Examples/20readexcel5.php new file mode 100644 index 0000000..d99b230 --- /dev/null +++ b/includes/PHPExcel/Examples/20readexcel5.php @@ -0,0 +1,79 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +if (!file_exists("14excel5.xls")) { + exit("Please run 14excel5.php first.\n"); +} + +echo date('H:i:s') , " Load workbook from Excel5 file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcel = PHPExcel_IOFactory::load("14excel5.xls"); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo 'Call time to load Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done reading file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/21pdf.php b/includes/PHPExcel/Examples/21pdf.php new file mode 100644 index 0000000..11c56b2 --- /dev/null +++ b/includes/PHPExcel/Examples/21pdf.php @@ -0,0 +1,94 @@ +'); + +date_default_timezone_set('Europe/London'); + +include "05featuredemo.inc.php"; + +/** PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +// Change these values to select the Rendering library that you wish to use +// and its directory location on your server +//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF; +//$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF; +$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF; +//$rendererLibrary = 'tcPDF5.9'; +//$rendererLibrary = 'mPDF5.4'; +$rendererLibrary = 'domPDF0.6.0beta3'; +$rendererLibraryPath = '/php/libraries/PDF/' . $rendererLibrary; + + +echo date('H:i:s') , " Hide grid lines" , EOL; +$objPHPExcel->getActiveSheet()->setShowGridLines(false); + +echo date('H:i:s') , " Set orientation to landscape" , EOL; +$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); + + +echo date('H:i:s') , " Write to PDF format using {$rendererName}" , EOL; + +if (!PHPExcel_Settings::setPdfRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); +$objWriter->setSheetIndex(0); +$objWriter->save(str_replace('.php', '_'.$rendererName.'.pdf', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo date('H:i:s') , " File written to " , str_replace('.php', '_'.$rendererName.'.pdf', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/22heavilyformatted.php b/includes/PHPExcel/Examples/22heavilyformatted.php new file mode 100644 index 0000000..c17bc86 --- /dev/null +++ b/includes/PHPExcel/Examples/22heavilyformatted.php @@ -0,0 +1,116 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); + +$objPHPExcel->getActiveSheet()->getStyle('A1:T100')->applyFromArray( + array('fill' => array( + 'type' => PHPExcel_Style_Fill::FILL_SOLID, + 'color' => array('argb' => 'FFCCFFCC') + ), + 'borders' => array( + 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + 'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM) + ) + ) + ); + +$objPHPExcel->getActiveSheet()->getStyle('C5:R95')->applyFromArray( + array('fill' => array( + 'type' => PHPExcel_Style_Fill::FILL_SOLID, + 'color' => array('argb' => 'FFFFFF00') + ), + ) + ); + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/23sharedstyles.php b/includes/PHPExcel/Examples/23sharedstyles.php new file mode 100644 index 0000000..652b4ed --- /dev/null +++ b/includes/PHPExcel/Examples/23sharedstyles.php @@ -0,0 +1,124 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0); + +$sharedStyle1 = new PHPExcel_Style(); +$sharedStyle2 = new PHPExcel_Style(); + +$sharedStyle1->applyFromArray( + array('fill' => array( + 'type' => PHPExcel_Style_Fill::FILL_SOLID, + 'color' => array('argb' => 'FFCCFFCC') + ), + 'borders' => array( + 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + 'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM) + ) + )); + +$sharedStyle2->applyFromArray( + array('fill' => array( + 'type' => PHPExcel_Style_Fill::FILL_SOLID, + 'color' => array('argb' => 'FFFFFF00') + ), + 'borders' => array( + 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), + 'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM) + ) + )); + +$objPHPExcel->getActiveSheet()->setSharedStyle($sharedStyle1, "A1:T100"); +$objPHPExcel->getActiveSheet()->setSharedStyle($sharedStyle2, "C5:R95"); + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/24readfilter.php b/includes/PHPExcel/Examples/24readfilter.php new file mode 100644 index 0000000..afa6d0c --- /dev/null +++ b/includes/PHPExcel/Examples/24readfilter.php @@ -0,0 +1,77 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +// Check prerequisites +if (!file_exists("06largescale.xlsx")) { + exit("Please run 06largescale.php first.\n"); +} + +class MyReadFilter implements PHPExcel_Reader_IReadFilter +{ + public function readCell($column, $row, $worksheetName = '') { + // Read title row and rows 20 - 30 + if ($row == 1 || ($row >= 20 && $row <= 30)) { + return true; + } + + return false; + } +} + + +echo date('H:i:s') , " Load from Excel2007 file" , EOL; +$objReader = PHPExcel_IOFactory::createReader('Excel2007'); +$objReader->setReadFilter( new MyReadFilter() ); +$objPHPExcel = $objReader->load("06largescale.xlsx"); + +echo date('H:i:s') , " Remove unnecessary rows" , EOL; +$objPHPExcel->getActiveSheet()->removeRow(2, 18); + +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/25inmemoryimage.php b/includes/PHPExcel/Examples/25inmemoryimage.php new file mode 100644 index 0000000..7a3424e --- /dev/null +++ b/includes/PHPExcel/Examples/25inmemoryimage.php @@ -0,0 +1,83 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + +// Generate an image +echo date('H:i:s') , " Generate an image" , EOL; +$gdImage = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream'); +$textColor = imagecolorallocate($gdImage, 255, 255, 255); +imagestring($gdImage, 1, 5, 5, 'Created with PHPExcel', $textColor); + +// Add a drawing to the worksheet +echo date('H:i:s') , " Add a drawing to the worksheet" , EOL; +$objDrawing = new PHPExcel_Worksheet_MemoryDrawing(); +$objDrawing->setName('Sample image'); +$objDrawing->setDescription('Sample image'); +$objDrawing->setImageResource($gdImage); +$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG); +$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT); +$objDrawing->setHeight(36); +$objDrawing->setWorksheet($objPHPExcel->getActiveSheet()); + +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/26utf8.php b/includes/PHPExcel/Examples/26utf8.php new file mode 100644 index 0000000..ad0b400 --- /dev/null +++ b/includes/PHPExcel/Examples/26utf8.php @@ -0,0 +1,122 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Change these values to select the PDF Rendering library that you wish to use +// and its directory location on your server +//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF; +//$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF; +$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF; +//$rendererLibrary = 'tcPDF5.9'; +//$rendererLibrary = 'mPDF5.4'; +$rendererLibrary = 'domPDF0.6.0beta3'; +$rendererLibraryPath = '/php/libraries/PDF/' . $rendererLibrary; + + +// Read from Excel2007 (.xlsx) template +echo date('H:i:s') , " Load Excel2007 template file" , EOL; +$objReader = PHPExcel_IOFactory::createReader('Excel2007'); +$objPHPExcel = $objReader->load("templates/26template.xlsx"); + +/** at this point, we could do some manipulations with the template, but we skip this step */ + +// Export to Excel2007 (.xlsx) +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Export to Excel5 (.xls) +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Export to HTML (.html) +echo date('H:i:s') , " Write to HTML format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); +$objWriter->save(str_replace('.php', '.htm', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.htm', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Export to PDF (.pdf) +echo date('H:i:s') , " Write to PDF format" , EOL; +try { + if (!PHPExcel_Settings::setPdfRenderer( + $rendererName, + $rendererLibraryPath + )) { + echo ( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + EOL . + 'at the top of this script as appropriate for your directory structure' . + EOL + ); + } else { + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); + $objWriter->save(str_replace('.php', '.pdf', __FILE__)); + echo date('H:i:s') , " File written to " , str_replace('.php', '.pdf', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + } +} catch (Exception $e) { + echo date('H:i:s') , ' EXCEPTION: ', $e->getMessage() , EOL; +} + +// Remove first two rows with field headers before exporting to CSV +echo date('H:i:s') , " Removing first two heading rows for CSV export" , EOL; +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->removeRow(1, 2); + +// Export to CSV (.csv) +echo date('H:i:s') , " Write to CSV format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV'); +$objWriter->save(str_replace('.php', '.csv', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Export to CSV with BOM (.csv) +echo date('H:i:s') , " Write to CSV format (with BOM)" , EOL; +$objWriter->setUseBOM(true); +$objWriter->save(str_replace('.php', '-bom.csv', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '-bom.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/27imagesexcel5.php b/includes/PHPExcel/Examples/27imagesexcel5.php new file mode 100644 index 0000000..17db771 --- /dev/null +++ b/includes/PHPExcel/Examples/27imagesexcel5.php @@ -0,0 +1,64 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Read from Excel5 (.xls) template +echo date('H:i:s') , " Load Excel2007 template file" , EOL; +$objReader = PHPExcel_IOFactory::createReader('Excel5'); +$objPHPExcel = $objReader->load("templates/27template.xls"); + +// Export to Excel2007 (.xlsx) +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Export to Excel5 (.xls) +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/28iterator.php b/includes/PHPExcel/Examples/28iterator.php new file mode 100644 index 0000000..3e1e681 --- /dev/null +++ b/includes/PHPExcel/Examples/28iterator.php @@ -0,0 +1,68 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +if (!file_exists("05featuredemo.xlsx")) { + exit("Please run 05featuredemo.php first." . EOL); +} + +echo date('H:i:s') , " Load from Excel2007 file" , EOL; +$objReader = PHPExcel_IOFactory::createReader('Excel2007'); +$objPHPExcel = $objReader->load("05featuredemo.xlsx"); + +echo date('H:i:s') , " Iterate worksheets" , EOL; +foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { + echo 'Worksheet - ' , $worksheet->getTitle() , EOL; + + foreach ($worksheet->getRowIterator() as $row) { + echo ' Row number - ' , $row->getRowIndex() , EOL; + + $cellIterator = $row->getCellIterator(); + $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set + foreach ($cellIterator as $cell) { + if (!is_null($cell)) { + echo ' Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue() , EOL; + } + } + } +} + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; diff --git a/includes/PHPExcel/Examples/29advancedvaluebinder.php b/includes/PHPExcel/Examples/29advancedvaluebinder.php new file mode 100644 index 0000000..bb387f9 --- /dev/null +++ b/includes/PHPExcel/Examples/29advancedvaluebinder.php @@ -0,0 +1,183 @@ +'); + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Set timezone +echo date('H:i:s') , " Set timezone" , EOL; +date_default_timezone_set('UTC'); + +// Set value binder +echo date('H:i:s') , " Set value binder" , EOL; +PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() ); + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") + ->setKeywords("office 2007 openxml php") + ->setCategory("Test result file"); + +// Set default font +echo date('H:i:s') , " Set default font" , EOL; +$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Arial'); +$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10); + +// Set column widths +echo date('H:i:s') , " Set column widths" , EOL; +$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); +$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(14); + +// Add some data, resembling some different data types +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String value:') + ->setCellValue('B1', 'Mark Baker'); + +$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Numeric value #1:') + ->setCellValue('B2', 12345); + +$objPHPExcel->getActiveSheet()->setCellValue('A3', 'Numeric value #2:') + ->setCellValue('B3', -12.345); + +$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Numeric value #3:') + ->setCellValue('B4', .12345); + +$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Numeric value #4:') + ->setCellValue('B5', '12345'); + +$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Numeric value #5:') + ->setCellValue('B6', '1.2345'); + +$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Numeric value #6:') + ->setCellValue('B7', '.12345'); + +$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Numeric value #7:') + ->setCellValue('B8', '1.234e-5'); + +$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Numeric value #8:') + ->setCellValue('B9', '-1.234e+5'); + +$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Boolean value:') + ->setCellValue('B10', 'TRUE'); + +$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Percentage value #1:') + ->setCellValue('B11', '10%'); + +$objPHPExcel->getActiveSheet()->setCellValue('A12', 'Percentage value #2:') + ->setCellValue('B12', '12.5%'); + +$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Fraction value #1:') + ->setCellValue('B13', '-1/2'); + +$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Fraction value #2:') + ->setCellValue('B14', '3 1/2'); + +$objPHPExcel->getActiveSheet()->setCellValue('A15', 'Fraction value #3:') + ->setCellValue('B15', '-12 3/4'); + +$objPHPExcel->getActiveSheet()->setCellValue('A16', 'Fraction value #4:') + ->setCellValue('B16', '13/4'); + +$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Currency value #1:') + ->setCellValue('B17', '$12345'); + +$objPHPExcel->getActiveSheet()->setCellValue('A18', 'Currency value #2:') + ->setCellValue('B18', '$12345.67'); + +$objPHPExcel->getActiveSheet()->setCellValue('A19', 'Currency value #3:') + ->setCellValue('B19', '$12,345.67'); + +$objPHPExcel->getActiveSheet()->setCellValue('A20', 'Date value #1:') + ->setCellValue('B20', '21 December 1983'); + +$objPHPExcel->getActiveSheet()->setCellValue('A21', 'Date value #2:') + ->setCellValue('B21', '19-Dec-1960'); + +$objPHPExcel->getActiveSheet()->setCellValue('A22', 'Date value #3:') + ->setCellValue('B22', '07/12/1982'); + +$objPHPExcel->getActiveSheet()->setCellValue('A23', 'Date value #4:') + ->setCellValue('B23', '24-11-1950'); + +$objPHPExcel->getActiveSheet()->setCellValue('A24', 'Date value #5:') + ->setCellValue('B24', '17-Mar'); + +$objPHPExcel->getActiveSheet()->setCellValue('A25', 'Time value #1:') + ->setCellValue('B25', '01:30'); + +$objPHPExcel->getActiveSheet()->setCellValue('A26', 'Time value #2:') + ->setCellValue('B26', '01:30:15'); + +$objPHPExcel->getActiveSheet()->setCellValue('A27', 'Date/Time value:') + ->setCellValue('B27', '19-Dec-1960 01:30'); + +$objPHPExcel->getActiveSheet()->setCellValue('A28', 'Formula:') + ->setCellValue('B28', '=SUM(B2:B9)'); + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Advanced value binder'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +// Save Excel5 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/30template.php b/includes/PHPExcel/Examples/30template.php new file mode 100644 index 0000000..33d553f --- /dev/null +++ b/includes/PHPExcel/Examples/30template.php @@ -0,0 +1,91 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + + +echo date('H:i:s') , " Load from Excel5 template" , EOL; +$objReader = PHPExcel_IOFactory::createReader('Excel5'); +$objPHPExcel = $objReader->load("templates/30template.xls"); + + + + +echo date('H:i:s') , " Add new data to the template" , EOL; +$data = array(array('title' => 'Excel for dummies', + 'price' => 17.99, + 'quantity' => 2 + ), + array('title' => 'PHP for dummies', + 'price' => 15.99, + 'quantity' => 1 + ), + array('title' => 'Inside OOP', + 'price' => 12.95, + 'quantity' => 1 + ) + ); + +$objPHPExcel->getActiveSheet()->setCellValue('D1', PHPExcel_Shared_Date::PHPToExcel(time())); + +$baseRow = 5; +foreach($data as $r => $dataRow) { + $row = $baseRow + $r; + $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1); + + $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1) + ->setCellValue('B'.$row, $dataRow['title']) + ->setCellValue('C'.$row, $dataRow['price']) + ->setCellValue('D'.$row, $dataRow['quantity']) + ->setCellValue('E'.$row, '=C'.$row.'*D'.$row); +} +$objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1); + + +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/31docproperties_write-xls.php b/includes/PHPExcel/Examples/31docproperties_write-xls.php new file mode 100644 index 0000000..cbb9aa3 --- /dev/null +++ b/includes/PHPExcel/Examples/31docproperties_write-xls.php @@ -0,0 +1,119 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$inputFileType = 'Excel5'; +$inputFileName = 'templates/31docproperties.xls'; + + +echo date('H:i:s') , " Load Tests from $inputFileType file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType); +$objPHPExcel = $objPHPExcelReader->load($inputFileName); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Adjust properties" , EOL; +$objPHPExcel->getProperties()->setTitle("Office 95 XLS Test Document") + ->setSubject("Office 95 XLS Test Document") + ->setDescription("Test XLS document, generated using PHPExcel") + ->setKeywords("office 95 biff php"); + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL; + + +echo EOL; +// Reread File +echo date('H:i:s') , " Reread Excel5 file" , EOL; +$objPHPExcelRead = PHPExcel_IOFactory::load(str_replace('.php', '.xls', __FILE__)); + +// Set properties +echo date('H:i:s') , " Get properties" , EOL; + +echo 'Core Properties:' , EOL; +echo ' Created by - ' , $objPHPExcel->getProperties()->getCreator() , EOL; +echo ' Created on - ' , date('d-M-Y',$objPHPExcel->getProperties()->getCreated()) , ' at ' , + date('H:i:s',$objPHPExcel->getProperties()->getCreated()) , EOL; +echo ' Last Modified by - ' , $objPHPExcel->getProperties()->getLastModifiedBy() , EOL; +echo ' Last Modified on - ' , date('d-M-Y',$objPHPExcel->getProperties()->getModified()) , ' at ' , + date('H:i:s',$objPHPExcel->getProperties()->getModified()) , EOL; +echo ' Title - ' , $objPHPExcel->getProperties()->getTitle() , EOL; +echo ' Subject - ' , $objPHPExcel->getProperties()->getSubject() , EOL; +echo ' Description - ' , $objPHPExcel->getProperties()->getDescription() , EOL; +echo ' Keywords: - ' , $objPHPExcel->getProperties()->getKeywords() , EOL; + + +echo 'Extended (Application) Properties:' , EOL; +echo ' Category - ' , $objPHPExcel->getProperties()->getCategory() , EOL; +echo ' Company - ' , $objPHPExcel->getProperties()->getCompany() , EOL; +echo ' Manager - ' , $objPHPExcel->getProperties()->getManager() , EOL; + + +echo 'Custom Properties:' , EOL; +$customProperties = $objPHPExcel->getProperties()->getCustomProperties(); +foreach($customProperties as $customProperty) { + $propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customProperty); + $propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customProperty); + echo ' ' , $customProperty , ' - (' , $propertyType , ') - '; + if ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE) { + echo date('d-M-Y H:i:s',$propertyValue) , EOL; + } elseif ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) { + echo (($propertyValue) ? 'TRUE' : 'FALSE') , EOL; + } else { + echo $propertyValue , EOL; + } +} + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL; diff --git a/includes/PHPExcel/Examples/31docproperties_write.php b/includes/PHPExcel/Examples/31docproperties_write.php new file mode 100644 index 0000000..1b01f6f --- /dev/null +++ b/includes/PHPExcel/Examples/31docproperties_write.php @@ -0,0 +1,119 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$inputFileType = 'Excel2007'; +$inputFileName = 'templates/31docproperties.xlsx'; + + +echo date('H:i:s') , " Load Tests from $inputFileType file" , EOL; +$callStartTime = microtime(true); + +$objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType); +$objPHPExcel = $objPHPExcelReader->load($inputFileName); + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +echo date('H:i:s') , " Adjust properties" , EOL; +$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document") + ->setSubject("Office 2007 XLSX Test Document") + ->setDescription("Test XLSX document, generated using PHPExcel") + ->setKeywords("office 2007 openxml php"); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL; + + +echo EOL; +// Reread File +echo date('H:i:s') , " Reread Excel2007 file" , EOL; +$objPHPExcelRead = PHPExcel_IOFactory::load(str_replace('.php', '.xlsx', __FILE__)); + +// Set properties +echo date('H:i:s') , " Get properties" , EOL; + +echo 'Core Properties:' , EOL; +echo ' Created by - ' , $objPHPExcel->getProperties()->getCreator() , EOL; +echo ' Created on - ' , date('d-M-Y',$objPHPExcel->getProperties()->getCreated()) , ' at ' , + date('H:i:s',$objPHPExcel->getProperties()->getCreated()) , EOL; +echo ' Last Modified by - ' , $objPHPExcel->getProperties()->getLastModifiedBy() , EOL; +echo ' Last Modified on - ' , date('d-M-Y',$objPHPExcel->getProperties()->getModified()) , ' at ' , + date('H:i:s',$objPHPExcel->getProperties()->getModified()) , EOL; +echo ' Title - ' , $objPHPExcel->getProperties()->getTitle() , EOL; +echo ' Subject - ' , $objPHPExcel->getProperties()->getSubject() , EOL; +echo ' Description - ' , $objPHPExcel->getProperties()->getDescription() , EOL; +echo ' Keywords: - ' , $objPHPExcel->getProperties()->getKeywords() , EOL; + + +echo 'Extended (Application) Properties:' , EOL; +echo ' Category - ' , $objPHPExcel->getProperties()->getCategory() , EOL; +echo ' Company - ' , $objPHPExcel->getProperties()->getCompany() , EOL; +echo ' Manager - ' , $objPHPExcel->getProperties()->getManager() , EOL; + + +echo 'Custom Properties:' , EOL; +$customProperties = $objPHPExcel->getProperties()->getCustomProperties(); +foreach($customProperties as $customProperty) { + $propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customProperty); + $propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customProperty); + echo ' ' , $customProperty , ' - (' , $propertyType , ') - '; + if ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE) { + echo date('d-M-Y H:i:s',$propertyValue) , EOL; + } elseif ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) { + echo (($propertyValue) ? 'TRUE' : 'FALSE') , EOL; + } else { + echo $propertyValue , EOL; + } +} + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL; diff --git a/includes/PHPExcel/Examples/32chartreadwrite.php b/includes/PHPExcel/Examples/32chartreadwrite.php new file mode 100644 index 0000000..e4c249d --- /dev/null +++ b/includes/PHPExcel/Examples/32chartreadwrite.php @@ -0,0 +1,131 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** Include path **/ +set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/'); + +/** PHPExcel_IOFactory */ +include 'PHPExcel/IOFactory.php'; + +$inputFileType = 'Excel2007'; +$inputFileNames = 'templates/32readwrite*[0-9].xlsx'; + +if ((isset($argc)) && ($argc > 1)) { + $inputFileNames = array(); + for($i = 1; $i < $argc; ++$i) { + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; + } +} else { + $inputFileNames = glob($inputFileNames); +} +foreach($inputFileNames as $inputFileName) { + $inputFileNameShort = basename($inputFileName); + + if (!file_exists($inputFileName)) { + echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL; + continue; + } + + echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL; + + $objReader = PHPExcel_IOFactory::createReader($inputFileType); + $objReader->setIncludeCharts(TRUE); + $objPHPExcel = $objReader->load($inputFileName); + + + echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL; + foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { + $sheetName = $worksheet->getTitle(); + echo 'Worksheet: ' , $sheetName , EOL; + + $chartNames = $worksheet->getChartNames(); + if(empty($chartNames)) { + echo ' There are no charts in this worksheet' , EOL; + } else { + natsort($chartNames); + foreach($chartNames as $i => $chartName) { + $chart = $worksheet->getChartByName($chartName); + if (!is_null($chart->getTitle())) { + $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"'; + } else { + $caption = 'Untitled'; + } + echo ' ' , $chartName , ' - ' , $caption , EOL; + echo str_repeat(' ',strlen($chartName)+3); + $groupCount = $chart->getPlotArea()->getPlotGroupCount(); + if ($groupCount == 1) { + $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); + echo ' ' , $chartType , EOL; + } else { + $chartTypes = array(); + for($i = 0; $i < $groupCount; ++$i) { + $chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType(); + } + $chartTypes = array_unique($chartTypes); + if (count($chartTypes) == 1) { + $chartType = 'Multiple Plot ' . array_pop($chartTypes); + echo ' ' , $chartType , EOL; + } elseif (count($chartTypes) == 0) { + echo ' *** Type not yet implemented' , EOL; + } else { + echo ' Combination Chart' , EOL; + } + } + } + } + } + + + $outputFileName = basename($inputFileName); + + echo date('H:i:s') , " Write Tests to Excel2007 file " , EOL; + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + $objWriter->setIncludeCharts(TRUE); + $objWriter->save($outputFileName); + echo date('H:i:s') , " File written to " , $outputFileName , EOL; + + $objPHPExcel->disconnectWorksheets(); + unset($objPHPExcel); +} + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-area.php b/includes/PHPExcel/Examples/33chartcreate-area.php new file mode 100644 index 0000000..53fe523 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-area.php @@ -0,0 +1,142 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_AREACHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test %age-Stacked Area Chart'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-bar-stacked.php b/includes/PHPExcel/Examples/33chartcreate-bar-stacked.php new file mode 100644 index 0000000..cac29f2 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-bar-stacked.php @@ -0,0 +1,145 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_STACKED, // plotGrouping + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); +// Set additional dataseries parameters +// Make it a horizontal bar rather than a vertical column graph +$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Chart'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-bar.php b/includes/PHPExcel/Examples/33chartcreate-bar.php new file mode 100644 index 0000000..14fd5d4 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-bar.php @@ -0,0 +1,145 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); +// Set additional dataseries parameters +// Make it a horizontal bar rather than a vertical column graph +$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_BAR); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Bar Chart'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-column-2.php b/includes/PHPExcel/Examples/33chartcreate-column-2.php new file mode 100644 index 0000000..00bf0d7 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-column-2.php @@ -0,0 +1,154 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', '', 'Budget', 'Forecast', 'Actual'), + array('2010', 'Q1', 47, 44, 43 ), + array('', 'Q2', 56, 53, 50 ), + array('', 'Q3', 52, 46, 45 ), + array('', 'Q4', 45, 40, 40 ), + array('2011', 'Q1', 51, 42, 46 ), + array('', 'Q2', 53, 58, 56 ), + array('', 'Q3', 64, 66, 69 ), + array('', 'Q4', 54, 55, 56 ), + array('2012', 'Q1', 49, 52, 58 ), + array('', 'Q2', 68, 73, 86 ), + array('', 'Q3', 72, 78, 0 ), + array('', 'Q4', 50, 60, 0 ), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 'Budget' + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 'Forecast' + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', NULL, 1), // 'Actual' +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$B$13', NULL, 12), // Q1 to Q4 for 2010 to 2012 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$13', NULL, 12), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); +// Set additional dataseries parameters +// Make it a vertical column rather than a horizontal bar graph +$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Grouped Column Chart'); +$xAxisLabel = new PHPExcel_Chart_Title('Financial Period'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + $xAxisLabel, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('G2'); +$chart->setBottomRightPosition('P20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-column.php b/includes/PHPExcel/Examples/33chartcreate-column.php new file mode 100644 index 0000000..ae9c618 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-column.php @@ -0,0 +1,145 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); +// Set additional dataseries parameters +// Make it a vertical column rather than a horizontal bar graph +$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Column Chart'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-composite.php b/includes/PHPExcel/Examples/33chartcreate-composite.php new file mode 100644 index 0000000..8ea7212 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-composite.php @@ -0,0 +1,203 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 'Rainfall (mm)', 'Temperature (°F)', 'Humidity (%)'), + array('Jan', 78, 52, 61), + array('Feb', 64, 54, 62), + array('Mar', 62, 57, 63), + array('Apr', 21, 62, 59), + array('May', 11, 75, 60), + array('Jun', 1, 75, 57), + array('Jul', 1, 79, 56), + array('Aug', 1, 79, 59), + array('Sep', 10, 75, 60), + array('Oct', 40, 68, 63), + array('Nov', 69, 62, 64), + array('Dec', 89, 57, 66), + ) +); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels1 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // Temperature +); +$dataSeriesLabels2 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // Rainfall +); +$dataSeriesLabels3 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // Humidity +); + +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$13', NULL, 12), // Jan to Dec +); + + +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues1 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', NULL, 12), +); + +// Build the dataseries +$series1 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping + range(0, count($dataSeriesValues1)-1), // plotOrder + $dataSeriesLabels1, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues1 // plotValues +); +// Set additional dataseries parameters +// Make it a vertical column rather than a horizontal bar graph +$series1->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL); + + +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues2 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12), +); + +// Build the dataseries +$series2 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping + range(0, count($dataSeriesValues2)-1), // plotOrder + $dataSeriesLabels2, // plotLabel + NULL, // plotCategory + $dataSeriesValues2 // plotValues +); + + +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues3 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12), +); + +// Build the dataseries +$series3 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_AREACHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping + range(0, count($dataSeriesValues2)-1), // plotOrder + $dataSeriesLabels3, // plotLabel + NULL, // plotCategory + $dataSeriesValues3 // plotValues +); + + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series1, $series2, $series3)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Average Weather Chart for Crete'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + NULL // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('F2'); +$chart->setBottomRightPosition('O16'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-line.php b/includes/PHPExcel/Examples/33chartcreate-line.php new file mode 100644 index 0000000..145ae72 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-line.php @@ -0,0 +1,142 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_STACKED, // plotGrouping + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Stacked Line Chart'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-multiple-charts.php b/includes/PHPExcel/Examples/33chartcreate-multiple-charts.php new file mode 100644 index 0000000..a95c276 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-multiple-charts.php @@ -0,0 +1,220 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels1 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues1 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues1 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series1 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_AREACHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping + range(0, count($dataSeriesValues1)-1), // plotOrder + $dataSeriesLabels1, // plotLabel + $xAxisTickValues1, // plotCategory + $dataSeriesValues1 // plotValues +); + +// Set the series in the plot area +$plotArea1 = new PHPExcel_Chart_PlotArea(NULL, array($series1)); +// Set the chart legend +$legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false); + +$title1 = new PHPExcel_Chart_Title('Test %age-Stacked Area Chart'); +$yAxisLabel1 = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart1 = new PHPExcel_Chart( + 'chart1', // name + $title1, // title + $legend1, // legend + $plotArea1, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel1 // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart1->setTopLeftPosition('A7'); +$chart1->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart1); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels2 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues2 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues2 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series2 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType + PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping + range(0, count($dataSeriesValues2)-1), // plotOrder + $dataSeriesLabels2, // plotLabel + $xAxisTickValues2, // plotCategory + $dataSeriesValues2 // plotValues +); +// Set additional dataseries parameters +// Make it a vertical column rather than a horizontal bar graph +$series2->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL); + +// Set the series in the plot area +$plotArea2 = new PHPExcel_Chart_PlotArea(NULL, array($series2)); +// Set the chart legend +$legend2 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title2 = new PHPExcel_Chart_Title('Test Column Chart'); +$yAxisLabel2 = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart2 = new PHPExcel_Chart( + 'chart2', // name + $title2, // title + $legend2, // legend + $plotArea2, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel2 // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart2->setTopLeftPosition('I7'); +$chart2->setBottomRightPosition('P20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart2); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-pie.php b/includes/PHPExcel/Examples/33chartcreate-pie.php new file mode 100644 index 0000000..5af0290 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-pie.php @@ -0,0 +1,215 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels1 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues1 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues1 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), +); + +// Build the dataseries +$series1 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_PIECHART, // plotType + NULL, // plotGrouping (Pie charts don't have any grouping) + range(0, count($dataSeriesValues1)-1), // plotOrder + $dataSeriesLabels1, // plotLabel + $xAxisTickValues1, // plotCategory + $dataSeriesValues1 // plotValues +); + +// Set up a layout object for the Pie chart +$layout1 = new PHPExcel_Chart_Layout(); +$layout1->setShowVal(TRUE); +$layout1->setShowPercent(TRUE); + +// Set the series in the plot area +$plotArea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1)); +// Set the chart legend +$legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title1 = new PHPExcel_Chart_Title('Test Pie Chart'); + + +// Create the chart +$chart1 = new PHPExcel_Chart( + 'chart1', // name + $title1, // title + $legend1, // legend + $plotArea1, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + NULL // yAxisLabel - Pie charts don't have a Y-Axis +); + +// Set the position where the chart should appear in the worksheet +$chart1->setTopLeftPosition('A7'); +$chart1->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart1); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels2 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues2 = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues2 = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), +); + +// Build the dataseries +$series2 = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_DONUTCHART, // plotType + NULL, // plotGrouping (Donut charts don't have any grouping) + range(0, count($dataSeriesValues2)-1), // plotOrder + $dataSeriesLabels2, // plotLabel + $xAxisTickValues2, // plotCategory + $dataSeriesValues2 // plotValues +); + +// Set up a layout object for the Pie chart +$layout2 = new PHPExcel_Chart_Layout(); +$layout2->setShowVal(TRUE); +$layout2->setShowCatName(TRUE); + +// Set the series in the plot area +$plotArea2 = new PHPExcel_Chart_PlotArea($layout2, array($series2)); + +$title2 = new PHPExcel_Chart_Title('Test Donut Chart'); + + +// Create the chart +$chart2 = new PHPExcel_Chart( + 'chart2', // name + $title2, // title + NULL, // legend + $plotArea2, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + NULL // yAxisLabel - Like Pie charts, Donut charts don't have a Y-Axis +); + +// Set the position where the chart should appear in the worksheet +$chart2->setTopLeftPosition('I7'); +$chart2->setBottomRightPosition('P20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart2); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-radar.php b/includes/PHPExcel/Examples/33chartcreate-radar.php new file mode 100644 index 0000000..b8b427f --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-radar.php @@ -0,0 +1,154 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Jan', 47, 45, 71), + array('Feb', 56, 73, 86), + array('Mar', 52, 61, 69), + array('Apr', 40, 52, 60), + array('May', 42, 55, 71), + array('Jun', 58, 63, 76), + array('Jul', 53, 61, 89), + array('Aug', 46, 69, 85), + array('Sep', 62, 75, 81), + array('Oct', 51, 70, 96), + array('Nov', 55, 66, 89), + array('Dec', 68, 62, 0), + ) +); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$13', NULL, 12), // Jan to Dec + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$13', NULL, 12), // Jan to Dec +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', NULL, 12), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', NULL, 12), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_RADARCHART, // plotType + NULL, // plotGrouping (Radar charts don't have any grouping) + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues, // plotValues + NULL, // smooth line + PHPExcel_Chart_DataSeries::STYLE_MARKER // plotStyle +); + +// Set up a layout object for the Pie chart +$layout = new PHPExcel_Chart_Layout(); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea($layout, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Radar Chart'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + NULL // yAxisLabel - Radar charts don't have a Y-Axis +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('F2'); +$chart->setBottomRightPosition('M15'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-scatter.php b/includes/PHPExcel/Examples/33chartcreate-scatter.php new file mode 100644 index 0000000..250c61d --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-scatter.php @@ -0,0 +1,138 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('', 2010, 2011, 2012), + array('Q1', 12, 15, 21), + array('Q2', 56, 73, 86), + array('Q3', 52, 61, 69), + array('Q4', 30, 32, 0), + ) +); + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011 + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012 +); +// Set the X-Axis Labels +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4 +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_SCATTERCHART, // plotType + NULL, // plotGrouping (Scatter charts don't have any grouping) + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues, // plotValues + NULL, // smooth line + PHPExcel_Chart_DataSeries::STYLE_LINEMARKER // plotStyle +); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Scatter Chart'); +$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); + + +// Create the chart +$chart = new PHPExcel_Chart( + 'chart1', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + NULL, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/33chartcreate-stock.php b/includes/PHPExcel/Examples/33chartcreate-stock.php new file mode 100644 index 0000000..b38fd51 --- /dev/null +++ b/includes/PHPExcel/Examples/33chartcreate-stock.php @@ -0,0 +1,151 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +$objPHPExcel = new PHPExcel(); +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array('Counts', 'Max', 'Min', 'Min Threshold', 'Max Threshold' ), + array(10, 10, 5, 0, 50 ), + array(30, 20, 10, 0, 50 ), + array(20, 30, 15, 0, 50 ), + array(40, 10, 0, 0, 50 ), + array(100, 40, 5, 0, 50 ), + ), null, 'A1', true +); +$objWorksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00); + + +// Set the Labels for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesLabels = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), //Max / Open + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), //Min / Close + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), //Min Threshold / Min + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$E$1', NULL, 1), //Max Threshold / Max +); +// Set the X-Axis Labels +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$xAxisTickValues = array( + new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$6', NULL, 5), // Counts +); +// Set the Data values for each data series we want to plot +// Datatype +// Cell reference for data +// Format Code +// Number of datapoints in series +// Data values +// Data Marker +$dataSeriesValues = array( + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$6', NULL, 5), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$6', NULL, 5), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$6', NULL, 5), + new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$E$2:$E$6', NULL, 5), +); + +// Build the dataseries +$series = new PHPExcel_Chart_DataSeries( + PHPExcel_Chart_DataSeries::TYPE_STOCKCHART, // plotType + null, // plotGrouping - if we set this to not null, then xlsx throws error + range(0, count($dataSeriesValues)-1), // plotOrder + $dataSeriesLabels, // plotLabel + $xAxisTickValues, // plotCategory + $dataSeriesValues // plotValues +); + +// Set the series in the plot area +$plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); +// Set the chart legend +$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false); + +$title = new PHPExcel_Chart_Title('Test Stock Chart'); +$xAxisLabel = new PHPExcel_Chart_Title('Counts'); +$yAxisLabel = new PHPExcel_Chart_Title('Values'); + +// Create the chart +$chart = new PHPExcel_Chart( + 'stock-chart', // name + $title, // title + $legend, // legend + $plotArea, // plotArea + true, // plotVisibleOnly + 0, // displayBlanksAs + $xAxisLabel, // xAxisLabel + $yAxisLabel // yAxisLabel +); + +// Set the position where the chart should appear in the worksheet +$chart->setTopLeftPosition('A7'); +$chart->setBottomRightPosition('H20'); + +// Add the chart to the worksheet +$objWorksheet->addChart($chart); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$filename = str_replace('.php', '.xlsx', __FILE__); +if(file_exists($filename)) { + unlink($filename); +} +$objWriter->save($filename); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/34chartupdate.php b/includes/PHPExcel/Examples/34chartupdate.php new file mode 100644 index 0000000..cb586a3 --- /dev/null +++ b/includes/PHPExcel/Examples/34chartupdate.php @@ -0,0 +1,78 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +if (!file_exists("33chartcreate-bar.xlsx")) { + exit("Please run 33chartcreate-bar.php first." . EOL); +} + +echo date('H:i:s') , " Load from Excel2007 file" , EOL; +$objReader = PHPExcel_IOFactory::createReader("Excel2007"); +$objReader->setIncludeCharts(TRUE); +$objPHPExcel = $objReader->load("33chartcreate-bar.xlsx"); + + +echo date('H:i:s') , " Update cell data values that are displayed in the chart" , EOL; +$objWorksheet = $objPHPExcel->getActiveSheet(); +$objWorksheet->fromArray( + array( + array(50-12, 50-15, 50-21), + array(50-56, 50-73, 50-86), + array(50-52, 50-61, 50-69), + array(50-30, 50-32, 50), + ), + NULL, + 'B2' +); + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->setIncludeCharts(TRUE); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/35chartrender.php b/includes/PHPExcel/Examples/35chartrender.php new file mode 100644 index 0000000..f0e7963 --- /dev/null +++ b/includes/PHPExcel/Examples/35chartrender.php @@ -0,0 +1,134 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** Include path **/ +set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/'); + +/** PHPExcel_IOFactory */ +include 'PHPExcel/IOFactory.php'; + + +// Change these values to select the Rendering library that you wish to use +// and its directory location on your server +$rendererName = PHPExcel_Settings::CHART_RENDERER_JPGRAPH; +$rendererLibrary = 'jpgraph3.5.0b1/src/'; +$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; + + +if (!PHPExcel_Settings::setChartRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + +$inputFileType = 'Excel2007'; +$inputFileNames = 'templates/32readwrite*[0-9].xlsx'; + + if ((isset($argc)) && ($argc > 1)) { + $inputFileNames = array(); + for($i = 1; $i < $argc; ++$i) { + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; + } +} else { + $inputFileNames = glob($inputFileNames); +} +foreach($inputFileNames as $inputFileName) { + $inputFileNameShort = basename($inputFileName); + + if (!file_exists($inputFileName)) { + echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL; + continue; + } + + echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL; + + $objReader = PHPExcel_IOFactory::createReader($inputFileType); + $objReader->setIncludeCharts(TRUE); + $objPHPExcel = $objReader->load($inputFileName); + + + echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL; + foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { + $sheetName = $worksheet->getTitle(); + echo 'Worksheet: ' , $sheetName , EOL; + + $chartNames = $worksheet->getChartNames(); + if(empty($chartNames)) { + echo ' There are no charts in this worksheet' , EOL; + } else { + natsort($chartNames); + foreach($chartNames as $i => $chartName) { + $chart = $worksheet->getChartByName($chartName); + if (!is_null($chart->getTitle())) { + $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"'; + } else { + $caption = 'Untitled'; + } + echo ' ' , $chartName , ' - ' , $caption , EOL; + echo str_repeat(' ',strlen($chartName)+3); + + $jpegFile = '35'.str_replace('.xlsx', '.jpg', substr($inputFileNameShort,2)); + if (file_exists($jpegFile)) { + unlink($jpegFile); + } + try { + $chart->render($jpegFile); + } catch (Exception $e) { + echo 'Error rendering chart: ',$e->getMessage(); + } + } + } + } + + + $objPHPExcel->disconnectWorksheets(); + unset($objPHPExcel); +} + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done rendering charts as images" , EOL; +echo 'Image files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/36chartreadwriteHTML.php b/includes/PHPExcel/Examples/36chartreadwriteHTML.php new file mode 100644 index 0000000..b4bae11 --- /dev/null +++ b/includes/PHPExcel/Examples/36chartreadwriteHTML.php @@ -0,0 +1,151 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** Include path **/ +set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/'); + +/** PHPExcel_IOFactory */ +include 'PHPExcel/IOFactory.php'; + + +// Change these values to select the Rendering library that you wish to use +// and its directory location on your server +$rendererName = PHPExcel_Settings::CHART_RENDERER_JPGRAPH; +$rendererLibrary = 'jpgraph3.5.0b1/src'; +$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; + + +if (!PHPExcel_Settings::setChartRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + +$inputFileType = 'Excel2007'; +$inputFileNames = 'templates/36write*.xlsx'; + +if ((isset($argc)) && ($argc > 1)) { + $inputFileNames = array(); + for($i = 1; $i < $argc; ++$i) { + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; + } +} else { + $inputFileNames = glob($inputFileNames); +} +foreach($inputFileNames as $inputFileName) { + $inputFileNameShort = basename($inputFileName); + + if (!file_exists($inputFileName)) { + echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL; + continue; + } + + echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL; + + $objReader = PHPExcel_IOFactory::createReader($inputFileType); + $objReader->setIncludeCharts(TRUE); + $objPHPExcel = $objReader->load($inputFileName); + + + echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL; + foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { + $sheetName = $worksheet->getTitle(); + echo 'Worksheet: ' , $sheetName , EOL; + + $chartNames = $worksheet->getChartNames(); + if(empty($chartNames)) { + echo ' There are no charts in this worksheet' , EOL; + } else { + natsort($chartNames); + foreach($chartNames as $i => $chartName) { + $chart = $worksheet->getChartByName($chartName); + if (!is_null($chart->getTitle())) { + $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"'; + } else { + $caption = 'Untitled'; + } + echo ' ' , $chartName , ' - ' , $caption , EOL; + echo str_repeat(' ',strlen($chartName)+3); + $groupCount = $chart->getPlotArea()->getPlotGroupCount(); + if ($groupCount == 1) { + $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); + echo ' ' , $chartType , EOL; + } else { + $chartTypes = array(); + for($i = 0; $i < $groupCount; ++$i) { + $chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType(); + } + $chartTypes = array_unique($chartTypes); + if (count($chartTypes) == 1) { + $chartType = 'Multiple Plot ' . array_pop($chartTypes); + echo ' ' , $chartType , EOL; + } elseif (count($chartTypes) == 0) { + echo ' *** Type not yet implemented' , EOL; + } else { + echo ' Combination Chart' , EOL; + } + } + } + } + } + + + $outputFileName = str_replace('.xlsx', '.html', basename($inputFileName)); + + echo date('H:i:s') , " Write Tests to HTML file " , EOL; + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML'); + $objWriter->setIncludeCharts(TRUE); + $objWriter->save($outputFileName); + echo date('H:i:s') , " File written to " , $outputFileName , EOL; + + $objPHPExcel->disconnectWorksheets(); + unset($objPHPExcel); +} + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/36chartreadwritePDF.php b/includes/PHPExcel/Examples/36chartreadwritePDF.php new file mode 100644 index 0000000..10d62cd --- /dev/null +++ b/includes/PHPExcel/Examples/36chartreadwritePDF.php @@ -0,0 +1,174 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** + * PHPExcel + * + * Copyright (C) 2006 - 2014 PHPExcel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## + */ + +/** Include path **/ +set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/'); + +/** PHPExcel_IOFactory */ +include 'PHPExcel/IOFactory.php'; + + +// Change these values to select the Rendering library that you wish to use +// for PDF files, and its directory location on your server +//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF; +$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF; +//$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF; +//$rendererLibrary = 'tcPDF5.9'; +$rendererLibrary = 'mPDF5.4'; +//$rendererLibrary = 'domPDF0.6.0beta3'; +$rendererLibraryPath = '/php/libraries/PDF/' . $rendererLibrary; + + +if (!PHPExcel_Settings::setPdfRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + +// Change these values to select the Rendering library that you wish to use +// for Chart images, and its directory location on your server +$rendererName = PHPExcel_Settings::CHART_RENDERER_JPGRAPH; +$rendererLibrary = 'jpgraph3.5.0b1/src'; +$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; + + +if (!PHPExcel_Settings::setChartRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + +$inputFileType = 'Excel2007'; +$inputFileNames = 'templates/36write*.xlsx'; + +if ((isset($argc)) && ($argc > 1)) { + $inputFileNames = array(); + for($i = 1; $i < $argc; ++$i) { + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; + } +} else { + $inputFileNames = glob($inputFileNames); +} +foreach($inputFileNames as $inputFileName) { + $inputFileNameShort = basename($inputFileName); + + if (!file_exists($inputFileName)) { + echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL; + continue; + } + + echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL; + + $objReader = PHPExcel_IOFactory::createReader($inputFileType); + $objReader->setIncludeCharts(TRUE); + $objPHPExcel = $objReader->load($inputFileName); + + + echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL; + foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { + $sheetName = $worksheet->getTitle(); + echo 'Worksheet: ' , $sheetName , EOL; + + $chartNames = $worksheet->getChartNames(); + if(empty($chartNames)) { + echo ' There are no charts in this worksheet' , EOL; + } else { + natsort($chartNames); + foreach($chartNames as $i => $chartName) { + $chart = $worksheet->getChartByName($chartName); + if (!is_null($chart->getTitle())) { + $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"'; + } else { + $caption = 'Untitled'; + } + echo ' ' , $chartName , ' - ' , $caption , EOL; + echo str_repeat(' ',strlen($chartName)+3); + $groupCount = $chart->getPlotArea()->getPlotGroupCount(); + if ($groupCount == 1) { + $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType(); + echo ' ' , $chartType , EOL; + } else { + $chartTypes = array(); + for($i = 0; $i < $groupCount; ++$i) { + $chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType(); + } + $chartTypes = array_unique($chartTypes); + if (count($chartTypes) == 1) { + $chartType = 'Multiple Plot ' . array_pop($chartTypes); + echo ' ' , $chartType , EOL; + } elseif (count($chartTypes) == 0) { + echo ' *** Type not yet implemented' , EOL; + } else { + echo ' Combination Chart' , EOL; + } + } + } + } + } + + + $outputFileName = str_replace('.xlsx', '.pdf', basename($inputFileName)); + + echo date('H:i:s') , " Write Tests to HTML file " , EOL; + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); + $objWriter->setIncludeCharts(TRUE); + $objWriter->save($outputFileName); + echo date('H:i:s') , " File written to " , $outputFileName , EOL; + + $objPHPExcel->disconnectWorksheets(); + unset($objPHPExcel); +} + +// Echo memory peak usage +echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/37page_layout_view.php b/includes/PHPExcel/Examples/37page_layout_view.php new file mode 100644 index 0000000..070f512 --- /dev/null +++ b/includes/PHPExcel/Examples/37page_layout_view.php @@ -0,0 +1,83 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("PHPOffice") + ->setLastModifiedBy("PHPOffice") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("Office PHPExcel php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!'); + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + +// Set the page layout view as page layout +$objPHPExcel->getActiveSheet()->getSheetView()->setView(PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_LAYOUT); + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +// Save Excel5 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/38cloneWorksheet.php b/includes/PHPExcel/Examples/38cloneWorksheet.php new file mode 100644 index 0000000..901b887 --- /dev/null +++ b/includes/PHPExcel/Examples/38cloneWorksheet.php @@ -0,0 +1,118 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("office PHPExcel php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', 'Hello') + ->setCellValue('B2', 'world!') + ->setCellValue('C1', 'Hello') + ->setCellValue('D2', 'world!'); + +// Miscellaneous glyphs, UTF-8 +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); + + +$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); +$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); +$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true); + + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Clone worksheet +echo date('H:i:s') , " Clone worksheet" , EOL; +$clonedSheet = clone $objPHPExcel->getActiveSheet(); +$clonedSheet + ->setCellValue('A1', 'Goodbye') + ->setCellValue('A2', 'cruel') + ->setCellValue('C1', 'Goodbye') + ->setCellValue('C2', 'cruel'); + +// Rename cloned worksheet +echo date('H:i:s') , " Rename cloned worksheet" , EOL; +$clonedSheet->setTitle('Simple Clone'); +$objPHPExcel->addSheet($clonedSheet); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/39dropdown.php b/includes/PHPExcel/Examples/39dropdown.php new file mode 100644 index 0000000..5dadc09 --- /dev/null +++ b/includes/PHPExcel/Examples/39dropdown.php @@ -0,0 +1,175 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties() + ->setCreator("PHPOffice") + ->setLastModifiedBy("PHPOffice") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("Office PHPExcel php") + ->setCategory("Test result file"); + + +function transpose($value) { + return array($value); +} + +// Add some data +$continentColumn = 'D'; +$column = 'F'; + +// Set data for dropdowns +foreach(glob('./data/continents/*') as $key => $filename) { + $continent = pathinfo($filename, PATHINFO_FILENAME); + echo "Loading $continent", EOL; + $continent = str_replace(' ','_',$continent); + $countries = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $countryCount = count($countries); + + // Transpose $countries from a row to a column array + $countries = array_map('transpose', $countries); + $objPHPExcel->getActiveSheet() + ->fromArray($countries, null, $column . '1'); + $objPHPExcel->addNamedRange( + new PHPExcel_NamedRange( + $continent, + $objPHPExcel->getActiveSheet(), $column . '1:' . $column . $countryCount + ) + ); + $objPHPExcel->getActiveSheet() + ->getColumnDimension($column) + ->setVisible(false); + + $objPHPExcel->getActiveSheet() + ->setCellValue($continentColumn . ($key+1), $continent); + + ++$column; +} + +// Hide the dropdown data +$objPHPExcel->getActiveSheet() + ->getColumnDimension($continentColumn) + ->setVisible(false); + +$objPHPExcel->addNamedRange( + new PHPExcel_NamedRange( + 'Continents', + $objPHPExcel->getActiveSheet(), $continentColumn . '1:' . $continentColumn . ($key+1) + ) +); + + +// Set selection cells +$objPHPExcel->getActiveSheet() + ->setCellValue('A1', 'Continent:'); +$objPHPExcel->getActiveSheet() + ->setCellValue('B1', 'Select continent'); +$objPHPExcel->getActiveSheet() + ->setCellValue('B3', '=' . $column . 1); +$objPHPExcel->getActiveSheet() + ->setCellValue('B3', 'Select country'); +$objPHPExcel->getActiveSheet() + ->getStyle('A1:A3') + ->getFont()->setBold(true); + +// Set linked validators +$objValidation = $objPHPExcel->getActiveSheet() + ->getCell('B1') + ->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ) + ->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ) + ->setAllowBlank(false) + ->setShowInputMessage(true) + ->setShowErrorMessage(true) + ->setShowDropDown(true) + ->setErrorTitle('Input error') + ->setError('Continent is not in the list.') + ->setPromptTitle('Pick from the list') + ->setPrompt('Please pick a continent from the drop-down list.') + ->setFormula1('=Continents'); + +$objPHPExcel->getActiveSheet() + ->setCellValue('A3', 'Country:'); +$objPHPExcel->getActiveSheet() + ->getStyle('A3') + ->getFont()->setBold(true); + +$objValidation = $objPHPExcel->getActiveSheet() + ->getCell('B3') + ->getDataValidation(); +$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_LIST ) + ->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_INFORMATION ) + ->setAllowBlank(false) + ->setShowInputMessage(true) + ->setShowErrorMessage(true) + ->setShowDropDown(true) + ->setErrorTitle('Input error') + ->setError('Country is not in the list.') + ->setPromptTitle('Pick from the list') + ->setPrompt('Please pick a country from the drop-down list.') + ->setFormula1('=INDIRECT($B$1)'); + + +$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12); +$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + +// Save Excel 2007 file +// This linked validation list method only seems to work for Excel2007, not for Excel5 +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/40duplicateStyle.php b/includes/PHPExcel/Examples/40duplicateStyle.php new file mode 100644 index 0000000..be31951 --- /dev/null +++ b/includes/PHPExcel/Examples/40duplicateStyle.php @@ -0,0 +1,51 @@ +'); + +date_default_timezone_set('Europe/London'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); +$worksheet = $objPHPExcel->getActiveSheet(); + +echo date('H:i:s') , " Create styles array" , EOL; +$styles = array(); +for ($i = 0; $i < 10; $i++) { + $style = new PHPExcel_Style(); + $style->getFont()->setSize($i + 4); + $styles[] = $style; +} + +echo date('H:i:s') , " Add data (begin)" , EOL; +$t = microtime(true); +for ($col = 0; $col < 50; $col++) { + for ($row = 0; $row < 100; $row++) { + $str = ($row + $col); + $style = $styles[$row % 10]; + $coord = PHPExcel_Cell::stringFromColumnIndex($col) . ($row + 1); + $worksheet->setCellValue($coord, $str); + $worksheet->duplicateStyle($style, $coord); + } +} +$d = microtime(true) - $t; +echo date('H:i:s') , " Add data (end), time: " . round($d, 2) . " s", EOL; + + +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; + + +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +echo date('H:i:s') , " Done writing file" , EOL; +echo 'File has been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/41password.php b/includes/PHPExcel/Examples/41password.php new file mode 100644 index 0000000..7b03e4f --- /dev/null +++ b/includes/PHPExcel/Examples/41password.php @@ -0,0 +1,84 @@ +'); + +date_default_timezone_set('Europe/London'); + +include "05featuredemo.inc.php"; + +/** Include PHPExcel_IOFactory */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php'; + + +// Set password against the spreadsheet file +$objPHPExcel->getSecurity()->setLockWindows(true); +$objPHPExcel->getSecurity()->setLockStructure(true); +$objPHPExcel->getSecurity()->setWorkbookPassword('secret'); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/42richText.php b/includes/PHPExcel/Examples/42richText.php new file mode 100644 index 0000000..4e99b85 --- /dev/null +++ b/includes/PHPExcel/Examples/42richText.php @@ -0,0 +1,159 @@ +'); + +/** Include PHPExcel */ +require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + + +// Create new PHPExcel object +echo date('H:i:s') , " Create new PHPExcel object" , EOL; +$objPHPExcel = new PHPExcel(); + +// Set document properties +echo date('H:i:s') , " Set document properties" , EOL; +$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PHPExcel Test Document") + ->setSubject("PHPExcel Test Document") + ->setDescription("Test document for PHPExcel, generated using PHP classes.") + ->setKeywords("office PHPExcel php") + ->setCategory("Test result file"); + + +// Add some data +echo date('H:i:s') , " Add some data" , EOL; + +$html1=' +

My very first example of rich text
generated from html markup

+

+ +This block contains an italicized word; +while this block uses an underline. + +

+

+I want to eat healthy foodpizza. + +'; + +$html2='

+ + 100°C is a hot temperature + +
+ + 10°F is cold + +

'; + +$html3='23 equals 8'; + +$html4='H2SO4 is the chemical formula for Sulphuric acid'; + + +$wizard = new PHPExcel_Helper_HTML; +$richText = $wizard->toRichTextObject($html1); + +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A1', $richText); + +$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(48); +$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1); +$objPHPExcel->getActiveSheet()->getStyle('A1') + ->getAlignment() + ->setWrapText(true); + +$richText = $wizard->toRichTextObject($html2); + +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A2', $richText); + +$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1); +$objPHPExcel->getActiveSheet()->getStyle('A2') + ->getAlignment() + ->setWrapText(true); + +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A3', $wizard->toRichTextObject($html3)); + +$objPHPExcel->setActiveSheetIndex(0) + ->setCellValue('A4', $wizard->toRichTextObject($html4)); + + +// Rename worksheet +echo date('H:i:s') , " Rename worksheet" , EOL; +$objPHPExcel->getActiveSheet()->setTitle('Simple'); + + +// Set active sheet index to the first sheet, so Excel opens this as the first sheet +$objPHPExcel->setActiveSheetIndex(0); + + +// Save Excel 2007 file +echo date('H:i:s') , " Write to Excel2007 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Save Excel 95 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; +$callStartTime = microtime(true); + +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; + +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; +echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; + +// Echo done +echo date('H:i:s') , " Done writing files" , EOL; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/includes/PHPExcel/Examples/Excel2003XMLReader.php b/includes/PHPExcel/Examples/Excel2003XMLReader.php new file mode 100644 index 0000000..00d96dd --- /dev/null +++ b/includes/PHPExcel/Examples/Excel2003XMLReader.php @@ -0,0 +1,61 @@ +load("Excel2003XMLTest.xml"); + + +$callEndTime = microtime(true); +$callTime = $callEndTime - $callStartTime; +echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , PHP_EOL; +// Echo memory usage +echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , PHP_EOL; + + +echo date('H:i:s') , " Write to Excel5 format" , PHP_EOL; +$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', __FILE__) , PHP_EOL; + + +// Echo memory peak usage +echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , PHP_EOL; + +// Echo done +echo date('H:i:s') , " Done writing file" , PHP_EOL; diff --git a/includes/PHPExcel/Examples/Excel2003XMLTest.xml b/includes/PHPExcel/Examples/Excel2003XMLTest.xml new file mode 100644 index 0000000..fb2d305 --- /dev/null +++ b/includes/PHPExcel/Examples/Excel2003XMLTest.xml @@ -0,0 +1 @@ +3#0000004#0000ff5#0080006#00ccff7#8000808#9933669#c0c0c010#c4751211#ccffcc12#ddbc7d13#ff000014#ff00ff15#ff660016#ff990017#ff99cc18#ffff0090001386024075FalseFalse + + + + + + + + + + + + + + + + + + + + + + + + + + + + Test String 1 + 1 + 5 + A + E + 6 + AE + + + Test - String 2 + 2 + 6 + B + F + 8 + BF + + + Test #3 + 3 + 7 + C + G + 10 + CG + + + Test with (") in string + 4 + 8 + D + H + 12 + DH + + + 10 + 26 + 36 + + + 1.23 + 1 + + + + 2.34 + 0 + + + 3.45 + + + + 1960-12-19T00:00:00.000 + TOP + #N/A + + + 1.5 + #DIV/0! + + + BOTTOM + + + LEFT + + + RIGHT + + + + BOX + + Test Column 1 + + + Test Column 2 + + + Test Column 3 + +
+ + +
+