From e87ec8505dcfc7518805e12104b0d13392ce70b7 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Wed, 17 Aug 2016 00:06:51 +0100 Subject: [PATCH] gh-17 Update examples for namespace changes --- Examples/01simple-download-ods.php | 53 +++-- Examples/01simple-download-pdf.php | 65 +++---- Examples/01simple-download-xls.php | 53 +++-- Examples/01simple-download-xlsx.php | 53 +++-- Examples/01simple.php | 55 +++--- Examples/01simplePCLZip.php | 63 +++--- Examples/02types-xls.php | 183 ------------------ Examples/02types.php | 124 ++++++------ Examples/03formulas.php | 118 ++++++----- Examples/04printing.php | 70 ++++--- ...excel_logo.gif => PhpSpreadsheet_logo.gif} | Bin 11 files changed, 344 insertions(+), 493 deletions(-) delete mode 100644 Examples/02types-xls.php rename Examples/images/{phpexcel_logo.gif => PhpSpreadsheet_logo.gif} (100%) diff --git a/Examples/01simple-download-ods.php b/Examples/01simple-download-ods.php index 397cd926..396ca5bd 100644 --- a/Examples/01simple-download-ods.php +++ b/Examples/01simple-download-ods.php @@ -1,8 +1,8 @@ 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"); +$objPhpSpreadsheet->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!'); +$objPhpSpreadsheet->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', 'éàèùâêîôûëïüÿäöüç'); +$objPhpSpreadsheet->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); // Rename worksheet -$objPHPExcel->getActiveSheet()->setTitle('Simple'); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->setActiveSheetIndex(0); // Redirect output to a client’s web browser (OpenDocument) @@ -84,6 +83,6 @@ 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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'OpenDocument'); $objWriter->save('php://output'); exit; diff --git a/Examples/01simple-download-pdf.php b/Examples/01simple-download-pdf.php index 6f33758d..b65ae75e 100644 --- a/Examples/01simple-download-pdf.php +++ b/Examples/01simple-download-pdf.php @@ -1,8 +1,8 @@ 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"); +$objPhpSpreadsheet->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!'); +$objPhpSpreadsheet->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', 'éàèùâêîôûëïüÿäöüç'); +$objPhpSpreadsheet->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); // Rename worksheet -$objPHPExcel->getActiveSheet()->setTitle('Simple'); -$objPHPExcel->getActiveSheet()->setShowGridLines(false); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Simple'); +$objPhpSpreadsheet->getActiveSheet()->setShowGridLines(false); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->setActiveSheetIndex(0); -if (!PHPExcel\Settings::setPdfRenderer( - $rendererName, +if (!PhpSpreadsheet\Settings::setPdfRenderer( + $rendererName, $rendererLibraryPath )) { die( @@ -99,6 +98,6 @@ 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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'PDF'); $objWriter->save('php://output'); exit; diff --git a/Examples/01simple-download-xls.php b/Examples/01simple-download-xls.php index 4a36411b..c1558366 100644 --- a/Examples/01simple-download-xls.php +++ b/Examples/01simple-download-xls.php @@ -1,8 +1,8 @@ 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"); +$objPhpSpreadsheet->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!'); +$objPhpSpreadsheet->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', 'éàèùâêîôûëïüÿäöüç'); +$objPhpSpreadsheet->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); // Rename worksheet -$objPHPExcel->getActiveSheet()->setTitle('Simple'); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel5) @@ -84,6 +83,6 @@ 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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5'); $objWriter->save('php://output'); exit; diff --git a/Examples/01simple-download-xlsx.php b/Examples/01simple-download-xlsx.php index 4a67f1e6..efc8ca69 100644 --- a/Examples/01simple-download-xlsx.php +++ b/Examples/01simple-download-xlsx.php @@ -1,8 +1,8 @@ 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"); +$objPhpSpreadsheet->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!'); +$objPhpSpreadsheet->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', 'éàèùâêîôûëïüÿäöüç'); +$objPhpSpreadsheet->setActiveSheetIndex(0) + ->setCellValue('A4', 'Miscellaneous glyphs') + ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); // Rename worksheet -$objPHPExcel->getActiveSheet()->setTitle('Simple'); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel2007) @@ -84,6 +83,6 @@ 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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); $objWriter->save('php://output'); exit; diff --git a/Examples/01simple.php b/Examples/01simple.php index a34b9634..4ccf8785 100644 --- a/Examples/01simple.php +++ b/Examples/01simple.php @@ -1,8 +1,8 @@ '); -/** Include PHPExcel */ +/** Include PhpSpreadsheet */ require_once dirname(__FILE__) . '/../src/Bootstrap.php'; -// Create new PHPExcel object -echo date('H:i:s') , " Create new PHPExcel object" , EOL; -$objPHPExcel = new \PHPExcel\Spreadsheet(); +// Create new Spreadsheet object +echo date('H:i:s') , " Create new Spreadsheet object" , EOL; +$objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet(); // Set document properties echo date('H:i:s') , " Set document properties" , EOL; -$objPHPExcel->getProperties() +$objPhpSpreadsheet->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") + ->setTitle("PhpSpreadsheet Test Document") + ->setSubject("PhpSpreadsheet Test Document") + ->setDescription("Test document for PhpSpreadsheet, generated using PHP classes.") + ->setKeywords("office PhpSpreadsheet php") ->setCategory("Test result file"); // Add some data echo date('H:i:s') , " Add some data" , EOL; -$objPHPExcel->setActiveSheetIndex(0) +$objPhpSpreadsheet->setActiveSheetIndex(0) ->setCellValue('A1', 'Hello') ->setCellValue('B2', 'world!') ->setCellValue('C1', 'Hello') ->setCellValue('D2', 'world!'); // Miscellaneous glyphs, UTF-8 -$objPHPExcel->setActiveSheetIndex(0) +$objPhpSpreadsheet->setActiveSheetIndex(0) ->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A8',"Hello\nWorld"); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getRowDimension(8) ->setRowHeight(-1); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getStyle('A8') ->getAlignment() ->setWrapText(true); $value = "-ValueA\n-Value B\n-Value C"; -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A10', $value); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getRowDimension(10) ->setRowHeight(-1); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getStyle('A10') ->getAlignment() ->setWrapText(true); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getStyle('A10') ->setQuotePrefix(true); // Rename worksheet echo date('H:i:s') , " Rename worksheet" , EOL; -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; @@ -122,7 +121,7 @@ echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 echo date('H:i:s') , " Write to Excel5 format" , EOL; $callStartTime = microtime(true); -$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5'); $objWriter->save(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; diff --git a/Examples/01simplePCLZip.php b/Examples/01simplePCLZip.php index 3ff31790..09915d4c 100644 --- a/Examples/01simplePCLZip.php +++ b/Examples/01simplePCLZip.php @@ -1,8 +1,8 @@ '); -/** Include PHPExcel */ +/** Include PhpSpreadsheet */ require_once dirname(__FILE__) . '/../src/Bootstrap.php'; -// Create new PHPExcel object -echo date('H:i:s') , " Create new PHPExcel object" , EOL; -$objPHPExcel = new \PHPExcel\Spreadsheet(); +// Create new PhpSpreadsheet object +echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL; +$objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet(); // 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"); +$objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw") + ->setLastModifiedBy("Maarten Balliauw") + ->setTitle("PhpSpreadsheet Test Document") + ->setSubject("PhpSpreadsheet Test Document") + ->setDescription("Test document for PhpSpreadsheet, generated using PHP classes.") + ->setKeywords("office PhpSpreadsheet 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!'); +$objPhpSpreadsheet->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', 'éàèùâêîôûëïüÿäöüç'); +$objPhpSpreadsheet->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); +$objPhpSpreadsheet->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); +$objPhpSpreadsheet->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); +$objPhpSpreadsheet->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true); // Rename worksheet echo date('H:i:s') , " Rename worksheet" , EOL; -$objPHPExcel->getActiveSheet()->setTitle('Simple'); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->setActiveSheetIndex(0); // Save Excel 2007 file @@ -85,9 +84,9 @@ 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); +PhpSpreadsheet\Settings::setZipClass(PhpSpreadsheet\Settings::PCLZIP); -$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); +$objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; diff --git a/Examples/02types-xls.php b/Examples/02types-xls.php deleted file mode 100644 index 5b0f9cf4..00000000 --- a/Examples/02types-xls.php +++ /dev/null @@ -1,183 +0,0 @@ -'); - -/** Include PHPExcel */ - require_once dirname(__FILE__) . '/../src/Bootstrap.php'; - - -// Create new PHPExcel object -echo date('H:i:s') , " Create new PHPExcel object" , EOL; -$objPHPExcel = new \PHPExcel\Spreadsheet(); - -// 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/Examples/02types.php b/Examples/02types.php index 596d9f1c..ca16d668 100644 --- a/Examples/02types.php +++ b/Examples/02types.php @@ -1,8 +1,8 @@ '); -/** Include PHPExcel */ +/** Include PhpSpreadsheet */ require_once dirname(__FILE__) . '/../src/Bootstrap.php'; -// Create new PHPExcel object -echo date('H:i:s') , " Create new PHPExcel object" , EOL; -$objPHPExcel = new \PHPExcel\Spreadsheet(); +// Create new PhpSpreadsheet object +echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL; +$objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet(); // Set document properties echo date('H:i:s') , " Set document properties" , EOL; -$objPHPExcel->getProperties() +$objPhpSpreadsheet->getProperties() ->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Test Document") @@ -54,144 +53,149 @@ $objPHPExcel->getProperties() // Set default font echo date('H:i:s') , " Set default font" , EOL; -$objPHPExcel->getDefaultStyle() +$objPhpSpreadsheet->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() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A1', 'String') ->setCellValue('B1', 'Simple') - ->setCellValue('C1', 'PHPExcel'); + ->setCellValue('C1', 'PhpSpreadsheet'); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A2', 'String') ->setCellValue('B2', 'Symbols') ->setCellValue('C2', '!+&=()~§±æþ'); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A3', 'String') ->setCellValue('B3', 'UTF-8') ->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов'); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A4', 'Number') ->setCellValue('B4', 'Integer') ->setCellValue('C4', 12); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A5', 'Number') ->setCellValue('B5', 'Float') ->setCellValue('C5', 34.56); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A6', 'Number') ->setCellValue('B6', 'Negative') ->setCellValue('C6', -7.89); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A7', 'Boolean') ->setCellValue('B7', 'True') ->setCellValue('C7', true); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A8', 'Boolean') ->setCellValue('B8', 'False') ->setCellValue('C8', false); $dateTimeNow = time(); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A9', 'Date/Time') ->setCellValue('B9', 'Date') - ->setCellValue('C9', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow )); -$objPHPExcel->getActiveSheet() + ->setCellValue('C9', \PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow )); +$objPhpSpreadsheet->getActiveSheet() ->getStyle('C9') ->getNumberFormat() - ->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); + ->setFormatCode(\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A10', 'Date/Time') ->setCellValue('B10', 'Time') - ->setCellValue('C10', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow )); -$objPHPExcel->getActiveSheet() + ->setCellValue('C10', \PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow )); +$objPhpSpreadsheet->getActiveSheet() ->getStyle('C10') ->getNumberFormat() - ->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_TIME4); + ->setFormatCode(\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A11', 'Date/Time') ->setCellValue('B11', 'Date and Time') - ->setCellValue('C11', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow )); -$objPHPExcel->getActiveSheet() + ->setCellValue('C11', \PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow )); +$objPhpSpreadsheet->getActiveSheet() ->getStyle('C11') ->getNumberFormat() - ->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_DATETIME); + ->setFormatCode(\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A12', 'NULL') ->setCellValue('C12', NULL); -$objRichText = new \PHPExcel\RichText(); +$objRichText = new \PhpSpreadsheet\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 ) ); +$objPayable->getFont()->setColor( new \PhpSpreadsheet\Style\Color( \PhpSpreadsheet\Style\Color::COLOR_DARKGREEN ) ); $objRichText->createText(', unless specified otherwise on the invoice.'); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->setCellValue('A13', 'Rich Text') ->setCellValue('C13', $objRichText); -$objRichText2 = new \PHPExcel\RichText(); +$objRichText2 = new \PhpSpreadsheet\RichText(); $objRichText2->createText("black text\n"); $objRed = $objRichText2->createTextRun("red text"); -$objRed->getFont()->setColor( new \PHPExcel\Style\Color(\PHPExcel\Style\Color::COLOR_RED ) ); +$objRed->getFont()->setColor( new \PhpSpreadsheet\Style\Color(\PhpSpreadsheet\Style\Color::COLOR_RED ) ); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getCell("C14") ->setValue($objRichText2); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getStyle("C14") ->getAlignment()->setWrapText(true); -$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Hyperlink'); +$objPhpSpreadsheet->getActiveSheet()->setCellValue('A17', 'Hyperlink'); -$objPHPExcel->getActiveSheet()->setCellValue('C17', 'www.phpexcel.net'); -$objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setUrl('http://www.phpexcel.net'); -$objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setTooltip('Navigate to website'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('C17', 'PhpSpreadsheet Web Site'); +$objPhpSpreadsheet->getActiveSheet() + ->getCell('C17') + ->getHyperlink() + ->setUrl('https://github.com/PHPOffice/PhpSpreadsheet') + ->setTooltip('Navigate to PhpSpreadsheet website'); -$objPHPExcel->getActiveSheet()->setCellValue('C18', '=HYPERLINK("mailto:abc@def.com","abc@def.com")'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('C18', '=HYPERLINK("mailto:abc@def.com","abc@def.com")'); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getColumnDimension('B') ->setAutoSize(true); -$objPHPExcel->getActiveSheet() +$objPhpSpreadsheet->getActiveSheet() ->getColumnDimension('C') ->setAutoSize(true); // Rename worksheet echo date('H:i:s') , " Rename worksheet" , EOL; -$objPHPExcel->getActiveSheet()->setTitle('Datatypes'); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Datatypes'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; @@ -202,24 +206,24 @@ echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" 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; +// Save Excel 5 file +echo date('H:i:s') , " Write to Excel5 format" , EOL; $callStartTime = microtime(true); -$objPHPExcel = \PHPExcel\IOFactory::load(str_replace('.php', '.xlsx', __FILE__)); - +$objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5'); +$objWriter->save(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; -echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; + +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; -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; +echo 'Files have been created in ' , getcwd() , EOL; diff --git a/Examples/03formulas.php b/Examples/03formulas.php index 6d3ef176..89283e59 100644 --- a/Examples/03formulas.php +++ b/Examples/03formulas.php @@ -1,8 +1,8 @@ '); -/** Include PHPExcel */ +/** Include PhpSpreadsheet */ require_once dirname(__FILE__) . '/../src/Bootstrap.php'; -// Create new PHPExcel object -echo date('H:i:s') , " Create new PHPExcel object" , EOL; -$objPHPExcel = new \PHPExcel\Spreadsheet(); +// Create new PhpSpreadsheet object +echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL; +$objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet(); // 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"); +$objPhpSpreadsheet->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:'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('A5', 'Sum:'); -$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range #1') - ->setCellValue('B2', 3) - ->setCellValue('B3', 7) - ->setCellValue('B4', 13) - ->setCellValue('B5', '=SUM(B2:B4)'); +$objPhpSpreadsheet->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; +$objPhpSpreadsheet->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)'); +$objPhpSpreadsheet->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; +$objPhpSpreadsheet->getActiveSheet() + ->getCell('C5') + ->getCalculatedValue() , EOL; -$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Total of both ranges:'); -$objPHPExcel->getActiveSheet()->setCellValue('B7', '=SUM(B5:C5)'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('A7', 'Total of both ranges:'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('B7', '=SUM(B5:C5)'); echo date('H:i:s') , " Sum of both Ranges is " , - $objPHPExcel->getActiveSheet()->getCell('B7')->getCalculatedValue() , EOL; +$objPhpSpreadsheet->getActiveSheet() + ->getCell('B7') + ->getCalculatedValue() , EOL; -$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Minimum of both ranges:'); -$objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C4)'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('A8', 'Minimum of both ranges:'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('B8', '=MIN(B2:C4)'); echo date('H:i:s') , " Minimum value in either Range is " , - $objPHPExcel->getActiveSheet()->getCell('B8')->getCalculatedValue() , EOL; +$objPhpSpreadsheet->getActiveSheet() + ->getCell('B8') + ->getCalculatedValue() , EOL; -$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Maximum of both ranges:'); -$objPHPExcel->getActiveSheet()->setCellValue('B9', '=MAX(B2:C4)'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('A9', 'Maximum of both ranges:'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('B9', '=MAX(B2:C4)'); echo date('H:i:s') , " Maximum value in either Range is " , - $objPHPExcel->getActiveSheet()->getCell('B9')->getCalculatedValue() , EOL; +$objPhpSpreadsheet->getActiveSheet() + ->getCell('B9') + ->getCalculatedValue() , EOL; -$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Average of both ranges:'); -$objPHPExcel->getActiveSheet()->setCellValue('B10', '=AVERAGE(B2:C4)'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('A10', 'Average of both ranges:'); +$objPhpSpreadsheet->getActiveSheet() + ->setCellValue('B10', '=AVERAGE(B2:C4)'); echo date('H:i:s') , " Average value of both Ranges is " , - $objPHPExcel->getActiveSheet()->getCell('B10')->getCalculatedValue() , EOL; +$objPhpSpreadsheet->getActiveSheet() + ->getCell('B10')->getCalculatedValue() , EOL; + + +$objPhpSpreadsheet->getActiveSheet() + ->getColumnDimension('A') + ->setAutoSize(true); // Rename worksheet echo date('H:i:s') , " Rename worksheet" , EOL; -$objPHPExcel->getActiveSheet()->setTitle('Formulas'); +$objPhpSpreadsheet->getActiveSheet() + ->setTitle('Formulas'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); // -// If we set Pre Calculated Formulas to true then PHPExcel will calculate all formulae in the +// If we set Pre Calculated Formulas to true then PhpSpreadsheet 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 @@ -130,7 +156,7 @@ echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 echo date('H:i:s') , " Write to Excel5 format" , EOL; $callStartTime = microtime(true); -$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5'); $objWriter->save(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; diff --git a/Examples/04printing.php b/Examples/04printing.php index c0d69fca..79edf444 100644 --- a/Examples/04printing.php +++ b/Examples/04printing.php @@ -1,8 +1,8 @@ '); date_default_timezone_set('Europe/London'); -/** Include PHPExcel */ +/** Include PhpSpreadsheet */ require_once dirname(__FILE__) . '/../src/Bootstrap.php'; -// Create new PHPExcel object -echo date('H:i:s') , " Create new PHPExcel object" , EOL; -$objPHPExcel = new \PHPExcel\Spreadsheet(); +// Create new PhpSpreadsheet object +echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL; +$objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet(); // 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"); +$objPhpSpreadsheet->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'); + $objPhpSpreadsheet->getActiveSheet()->setCellValue('A' . $i, $i); + $objPhpSpreadsheet->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'); +$objPhpSpreadsheet->getActiveSheet() + ->getHeaderFooter() + ->setOddHeader('&L&G&C&HPlease treat this document as confidential!'); +$objPhpSpreadsheet->getActiveSheet() + ->getHeaderFooter() + ->setOddFooter('&L&B' . $objPhpSpreadsheet->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 = new \PhpSpreadsheet\Worksheet\HeaderFooterDrawing(); +$objDrawing->setName('PhpSpreadsheet logo'); +$objDrawing->setPath('./images/PhpSpreadsheet_logo.gif'); $objDrawing->setHeight(36); -$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, \PHPExcel\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT); +$objPhpSpreadsheet->getActiveSheet() + ->getHeaderFooter() + ->addImage($objDrawing, \PhpSpreadsheet\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); +$objPhpSpreadsheet->getActiveSheet() + ->getPageSetup() + ->setOrientation(\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); +$objPhpSpreadsheet->getActiveSheet() + ->getPageSetup() + ->setPaperSize(\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); // Rename worksheet echo date('H:i:s') , " Rename worksheet" , EOL; -$objPHPExcel->getActiveSheet()->setTitle('Printing'); +$objPhpSpreadsheet->getActiveSheet()->setTitle('Printing'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet -$objPHPExcel->setActiveSheetIndex(0); +$objPhpSpreadsheet->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 = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; @@ -106,7 +116,7 @@ echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 echo date('H:i:s') , " Write to Excel5 format" , EOL; $callStartTime = microtime(true); -$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); +$objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5'); $objWriter->save(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; diff --git a/Examples/images/phpexcel_logo.gif b/Examples/images/PhpSpreadsheet_logo.gif similarity index 100% rename from Examples/images/phpexcel_logo.gif rename to Examples/images/PhpSpreadsheet_logo.gif