Modify Test examples to echo nicely from both CLI and in a web browser

This commit is contained in:
Mark Baker 2012-08-05 23:03:45 +01:00
parent 0588576fe2
commit cf78af261c
19 changed files with 334 additions and 241 deletions

View File

@ -29,7 +29,6 @@
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

View File

@ -27,6 +27,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -100,4 +105,4 @@ echo 'Value of B14 [=COUNT(B2:B12)]: ' . $objPHPExcel->getActiveSheet()->getCell
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.\r\n";
echo date('H:i:s') . " Done" , EOL;

View File

@ -27,6 +27,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,11 +40,11 @@ require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object
echo date('H:i:s') , " Create new PHPExcel object" , PHP_EOL;
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new PHPExcel();
// Set document properties
echo date('H:i:s') , " Set document properties" , PHP_EOL;
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
@ -50,7 +55,7 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data
echo date('H:i:s') , " Add some data" , PHP_EOL;
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:')
->setCellValue('A2', 'Lastname:')
@ -60,25 +65,25 @@ $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:')
->setCellValue('B3', '=B1 & " " & B2');
// Define named ranges
echo date('H:i:s') , " Define named ranges" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Rename named ranges" , EOL;
$objPHPExcel->getNamedRange('PersonName')->setName('PersonFN');
// Rename worksheet
echo date('H:i:s') , " Rename worksheet" , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:')
->setCellValue('A2', 'Lastname:')
@ -88,13 +93,13 @@ $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Firstname:')
->setCellValue('B3', '=PersonFN & " " & PersonLN');
// Resolve range
echo date('H:i:s') , " Resolve range" , PHP_EOL;
echo 'Cell B1 {=PersonFN}: ' , $objPHPExcel->getActiveSheet()->getCell('B1')->getCalculatedValue() , PHP_EOL;
echo 'Cell B3 {=PersonFN & " " & PersonLN}: ' , $objPHPExcel->getActiveSheet()->getCell('B3')->getCalculatedValue() , PHP_EOL;
echo 'Cell Person!B1: ' , $objPHPExcel->getActiveSheet()->getCell('Person!B1')->getCalculatedValue() , PHP_EOL;
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" , PHP_EOL;
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
@ -102,14 +107,15 @@ $objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -38,17 +43,18 @@ if (!file_exists("14excel5.xls")) {
exit("Please run 14excel5.php first.\n");
}
echo date('H:i:s') , " Load workbook from Excel5 file" , PHP_EOL;
echo date('H:i:s') , " Load workbook from Excel5 file" , EOL;
$objPHPExcel = PHPExcel_IOFactory::load("14excel5.xls");
echo date('H:i:s') , " Write to Excel2007 format" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done reading file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -46,14 +51,14 @@ $rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary;
echo date('H:i:s') , " Hide grid lines" , PHP_EOL;
echo date('H:i:s') , " Hide grid lines" , EOL;
$objPHPExcel->getActiveSheet()->setShowGridLines(false);
echo date('H:i:s') , " Set orientation to landscape" , PHP_EOL;
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}" , PHP_EOL;
echo date('H:i:s') , " Write to PDF format using {$rendererName}" , EOL;
if (!PHPExcel_Settings::setPdfRenderer(
$rendererName,
@ -61,7 +66,7 @@ if (!PHPExcel_Settings::setPdfRenderer(
)) {
die(
'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
PHP_EOL .
EOL .
'at the top of this script as appropriate for your directory structure'
);
}
@ -70,11 +75,12 @@ if (!PHPExcel_Settings::setPdfRenderer(
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setSheetIndex(0);
$objWriter->save(str_replace('.php', '_'.$rendererName.'.pdf', __FILE__));
echo date('H:i:s') , " File written to " , str_replace('.php', '_'.$rendererName.'.pdf', __FILE__) , PHP_EOL;
echo date('H:i:s') , " File written to " , str_replace('.php', '_'.$rendererName.'.pdf', 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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing files" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,11 +40,11 @@ require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object
echo date('H:i:s') , " Create new PHPExcel object" , PHP_EOL;
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new PHPExcel();
// Set document properties
echo date('H:i:s') , " Set document properties" , PHP_EOL;
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
@ -50,7 +55,7 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data
echo date('H:i:s') , " Add some data" , PHP_EOL;
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->getStyle('A1:T100')->applyFromArray(
@ -74,14 +79,15 @@ $objPHPExcel->getActiveSheet()->getStyle('C5:R95')->applyFromArray(
);
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,11 +40,11 @@ require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object
echo date('H:i:s') , " Create new PHPExcel object" , PHP_EOL;
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new PHPExcel();
// Set document properties
echo date('H:i:s') , " Set document properties" , PHP_EOL;
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
@ -50,7 +55,7 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data
echo date('H:i:s') , " Add some data" , PHP_EOL;
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0);
$sharedStyle1 = new PHPExcel_Style();
@ -82,14 +87,15 @@ $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" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -26,6 +26,10 @@
*/
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -51,22 +55,23 @@ class MyReadFilter implements PHPExcel_Reader_IReadFilter
}
echo date('H:i:s') , " Load from Excel2007 file" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Remove unnecessary rows" , EOL;
$objPHPExcel->getActiveSheet()->removeRow(2, 18);
echo date('H:i:s') , " Write to Excel2007 format" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,11 +39,11 @@ require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object
echo date('H:i:s') , " Create new PHPExcel object" , PHP_EOL;
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new PHPExcel();
// Set document properties
echo date('H:i:s') , " Set document properties" , PHP_EOL;
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
@ -49,13 +53,13 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setCategory("Test result file");
// Generate an image
echo date('H:i:s') , " Generate an image" , PHP_EOL;
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" , PHP_EOL;
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');
@ -65,14 +69,15 @@ $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(36);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
echo date('H:i:s') , " Write to Excel2007 format" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -46,32 +50,32 @@ $rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererL
// Read from Excel2007 (.xlsx) template
echo date('H:i:s') , " Load Excel2007 template file" , PHP_EOL;
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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Write to PDF format" , EOL;
try {
if (!PHPExcel_Settings::setPdfRenderer(
$rendererName,
@ -79,38 +83,40 @@ try {
)) {
echo (
'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
PHP_EOL .
'at the top of this script as appropriate for your directory structure'
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', __FILE__) , PHP_EOL;
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() , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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)" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing files" , EOL;
echo 'Files have been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,25 +39,26 @@ require_once '../Classes/PHPExcel.php';
// Read from Excel5 (.xls) template
echo date('H:i:s') , " Load Excel2007 template file" , PHP_EOL;
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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing files" , EOL;
echo 'Files have been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,25 +39,25 @@ require_once '../Classes/PHPExcel/IOFactory.php';
if (!file_exists("05featuredemo.xlsx")) {
exit("Please run 05featuredemo.php first." . PHP_EOL);
exit("Please run 05featuredemo.php first." . EOL);
}
echo date('H:i:s') , " Load from Excel2007 file" , PHP_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" , PHP_EOL;
echo date('H:i:s') , " Iterate worksheets" , EOL;
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
echo 'Worksheet - ' , $worksheet->getTitle() , PHP_EOL;
echo 'Worksheet - ' , $worksheet->getTitle() , EOL;
foreach ($worksheet->getRowIterator() as $row) {
echo ' Row number - ' , $row->getRowIndex() , PHP_EOL;
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() , PHP_EOL;
echo ' Cell - ' , $cell->getCoordinate() , ' - ' , $cell->getCalculatedValue() , EOL;
}
}
}
@ -61,4 +65,4 @@ foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , PHP_EOL;
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;

View File

@ -27,27 +27,29 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** PHPExcel */
require_once '../Classes/PHPExcel.php';
// Set timezone
echo date('H:i:s') , " Set timezone" , PHP_EOL;
echo date('H:i:s') , " Set timezone" , EOL;
date_default_timezone_set('UTC');
// Set value binder
echo date('H:i:s') , " Set value binder" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new PHPExcel();
// Set document properties
echo date('H:i:s') , " Set document properties" , PHP_EOL;
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
@ -57,85 +59,85 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setCategory("Test result file");
// Set default font
echo date('H:i:s') , " Set default font" , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String value:');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Mark Baker');
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:');
$objPHPExcel->getActiveSheet()->setCellValue('B2', 12345);
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Numeric value #1:')
->setCellValue('B2', 12345);
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'Numeric value #2:');
$objPHPExcel->getActiveSheet()->setCellValue('B3', -12.345);
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'Numeric value #2:')
->setCellValue('B3', -12.345);
$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Numeric value #3:');
$objPHPExcel->getActiveSheet()->setCellValue('B4', .12345);
$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Numeric value #3:')
->setCellValue('B4', .12345);
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Numeric value #4:');
$objPHPExcel->getActiveSheet()->setCellValue('B5', '12345');
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Numeric value #4:')
->setCellValue('B5', '12345');
$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Numeric value #5:');
$objPHPExcel->getActiveSheet()->setCellValue('B6', '1.2345');
$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Numeric value #5:')
->setCellValue('B6', '1.2345');
$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Numeric value #6:');
$objPHPExcel->getActiveSheet()->setCellValue('B7', '.12345');
$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Numeric value #6:')
->setCellValue('B7', '.12345');
$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Numeric value #7:');
$objPHPExcel->getActiveSheet()->setCellValue('B8', '1.234e-5');
$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Numeric value #7:')
->setCellValue('B8', '1.234e-5');
$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Numeric value #8:');
$objPHPExcel->getActiveSheet()->setCellValue('B9', '-1.234e+5');
$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Numeric value #8:')
->setCellValue('B9', '-1.234e+5');
$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Boolean value:');
$objPHPExcel->getActiveSheet()->setCellValue('B10', true);
$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Boolean value:')
->setCellValue('B10', true);
$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Percentage value #1:');
$objPHPExcel->getActiveSheet()->setCellValue('B11', '10%');
$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Percentage value #1:')
->setCellValue('B11', '10%');
$objPHPExcel->getActiveSheet()->setCellValue('A12', 'Percentage value #2:');
$objPHPExcel->getActiveSheet()->setCellValue('B12', '12.5%');
$objPHPExcel->getActiveSheet()->setCellValue('A12', 'Percentage value #2:')
->setCellValue('B12', '12.5%');
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Currency value:');
$objPHPExcel->getActiveSheet()->setCellValue('B13', '$12345');
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Currency value:')
->setCellValue('B13', '$12345');
$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Date value #1:');
$objPHPExcel->getActiveSheet()->setCellValue('B14', '21 December 1983');
$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Date value #1:')
->setCellValue('B14', '21 December 1983');
$objPHPExcel->getActiveSheet()->setCellValue('A15', 'Date value #2:');
$objPHPExcel->getActiveSheet()->setCellValue('B15', '19-Dec-1960');
$objPHPExcel->getActiveSheet()->setCellValue('A15', 'Date value #2:')
->setCellValue('B15', '19-Dec-1960');
$objPHPExcel->getActiveSheet()->setCellValue('A16', 'Date value #3:');
$objPHPExcel->getActiveSheet()->setCellValue('B16', '19/12/1960');
$objPHPExcel->getActiveSheet()->setCellValue('A16', 'Date value #3:')
->setCellValue('B16', '19/12/1960');
$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Date value #4:');
$objPHPExcel->getActiveSheet()->setCellValue('B17', '19-12-1960');
$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Date value #4:')
->setCellValue('B17', '19-12-1960');
$objPHPExcel->getActiveSheet()->setCellValue('A18', 'Date value #5:');
$objPHPExcel->getActiveSheet()->setCellValue('B18', '1-Jan');
$objPHPExcel->getActiveSheet()->setCellValue('A18', 'Date value #5:')
->setCellValue('B18', '1-Jan');
$objPHPExcel->getActiveSheet()->setCellValue('A19', 'Time value #1:');
$objPHPExcel->getActiveSheet()->setCellValue('B19', '01:30');
$objPHPExcel->getActiveSheet()->setCellValue('A19', 'Time value #1:')
->setCellValue('B19', '01:30');
$objPHPExcel->getActiveSheet()->setCellValue('A20', 'Time value #2:');
$objPHPExcel->getActiveSheet()->setCellValue('B20', '01:30:15');
$objPHPExcel->getActiveSheet()->setCellValue('A20', 'Time value #2:')
->setCellValue('B20', '01:30:15');
$objPHPExcel->getActiveSheet()->setCellValue('A21', 'Date/Time value:');
$objPHPExcel->getActiveSheet()->setCellValue('B21', '19-Dec-1960 01:30');
$objPHPExcel->getActiveSheet()->setCellValue('A21', 'Date/Time value:')
->setCellValue('B21', '19-Dec-1960 01:30');
$objPHPExcel->getActiveSheet()->setCellValue('A22', 'Formula:');
$objPHPExcel->getActiveSheet()->setCellValue('B22', '=SUM(B2:B9)');
$objPHPExcel->getActiveSheet()->setCellValue('A22', 'Formula:')
->setCellValue('B22', '=SUM(B2:B9)');
// Rename worksheet
echo date('H:i:s') , " Rename worksheet" , PHP_EOL;
echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('Advanced value binder');
@ -144,14 +146,15 @@ $objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel5 format" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -35,14 +39,14 @@ require_once '../Classes/PHPExcel/IOFactory.php';
echo date('H:i:s') , " Load from Excel5 template" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Add new data to the template" , EOL;
$data = array(array('title' => 'Excel for dummies',
'price' => 17.99,
'quantity' => 2
@ -64,23 +68,24 @@ foreach($data as $r => $dataRow) {
$row = $baseRow + $r;
$objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$row, $dataRow['title']);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $dataRow['price']);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $dataRow['quantity']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, '=C'.$row.'*D'.$row);
$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" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -38,7 +42,7 @@ $inputFileType = 'Excel5';
$inputFileName = 'templates/31docproperties.xls';
echo date('H:i:s') , " Load Tests from $inputFileType file" , PHP_EOL;
echo date('H:i:s') , " Load Tests from $inputFileType file" , EOL;
$callStartTime = microtime(true);
$objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
@ -46,12 +50,12 @@ $objPHPExcel = $objPHPExcelReader->load($inputFileName);
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
echo date('H:i:s') , " Adjust properties" , PHP_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")
@ -59,57 +63,57 @@ $objPHPExcel->getProperties()->setTitle("Office 95 XLS Test Document")
// Save Excel 95 file
echo date('H:i:s') , " Write to Excel5 format" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL;
echo PHP_EOL;
echo EOL;
// Reread File
echo date('H:i:s') , " Reread Excel5 file" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Get properties" , EOL;
echo 'Core Properties:' , PHP_EOL;
echo ' Created by - ' , $objPHPExcel->getProperties()->getCreator() , PHP_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()) , PHP_EOL;
echo ' Last Modified by - ' , $objPHPExcel->getProperties()->getLastModifiedBy() , PHP_EOL;
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()) , PHP_EOL;
echo ' Title - ' , $objPHPExcel->getProperties()->getTitle() , PHP_EOL;
echo ' Subject - ' , $objPHPExcel->getProperties()->getSubject() , PHP_EOL;
echo ' Description - ' , $objPHPExcel->getProperties()->getDescription() , PHP_EOL;
echo ' Keywords: - ' , $objPHPExcel->getProperties()->getKeywords() , PHP_EOL;
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:' , PHP_EOL;
echo ' Category - ' , $objPHPExcel->getProperties()->getCategory() , PHP_EOL;
echo ' Company - ' , $objPHPExcel->getProperties()->getCompany() , PHP_EOL;
echo ' Manager - ' , $objPHPExcel->getProperties()->getManager() , PHP_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:' , PHP_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) , PHP_EOL;
echo date('d-M-Y H:i:s',$propertyValue) , EOL;
} elseif ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) {
echo (($propertyValue) ? 'TRUE' : 'FALSE') , PHP_EOL;
echo (($propertyValue) ? 'TRUE' : 'FALSE') , EOL;
} else {
echo $propertyValue , PHP_EOL;
echo $propertyValue , EOL;
}
}
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , PHP_EOL;
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL;

View File

@ -27,6 +27,10 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -38,7 +42,7 @@ $inputFileType = 'Excel2007';
$inputFileName = 'templates/31docproperties.xlsx';
echo date('H:i:s') , " Load Tests from $inputFileType file" , PHP_EOL;
echo date('H:i:s') , " Load Tests from $inputFileType file" , EOL;
$callStartTime = microtime(true);
$objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
@ -46,12 +50,12 @@ $objPHPExcel = $objPHPExcelReader->load($inputFileName);
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
echo date('H:i:s') , " Adjust properties" , PHP_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")
@ -59,57 +63,57 @@ $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document")
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , PHP_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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL;
echo PHP_EOL;
echo EOL;
// Reread File
echo date('H:i:s') , " Reread Excel2007 file" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Get properties" , EOL;
echo 'Core Properties:' , PHP_EOL;
echo ' Created by - ' , $objPHPExcel->getProperties()->getCreator() , PHP_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()) , PHP_EOL;
echo ' Last Modified by - ' , $objPHPExcel->getProperties()->getLastModifiedBy() , PHP_EOL;
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()) , PHP_EOL;
echo ' Title - ' , $objPHPExcel->getProperties()->getTitle() , PHP_EOL;
echo ' Subject - ' , $objPHPExcel->getProperties()->getSubject() , PHP_EOL;
echo ' Description - ' , $objPHPExcel->getProperties()->getDescription() , PHP_EOL;
echo ' Keywords: - ' , $objPHPExcel->getProperties()->getKeywords() , PHP_EOL;
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:' , PHP_EOL;
echo ' Category - ' , $objPHPExcel->getProperties()->getCategory() , PHP_EOL;
echo ' Company - ' , $objPHPExcel->getProperties()->getCompany() , PHP_EOL;
echo ' Manager - ' , $objPHPExcel->getProperties()->getManager() , PHP_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:' , PHP_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) , PHP_EOL;
echo date('d-M-Y H:i:s',$propertyValue) , EOL;
} elseif ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) {
echo (($propertyValue) ? 'TRUE' : 'FALSE') , PHP_EOL;
echo (($propertyValue) ? 'TRUE' : 'FALSE') , EOL;
} else {
echo $propertyValue , PHP_EOL;
echo $propertyValue , EOL;
}
}
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , PHP_EOL;
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL;

View File

@ -2,6 +2,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -52,25 +57,25 @@ foreach($inputFileNames as $inputFileName) {
$inputFileNameShort = basename($inputFileName);
if (!file_exists($inputFileName)) {
echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , PHP_EOL;
echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL;
continue;
}
echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL;
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$sheetName = $worksheet->getTitle();
echo 'Worksheet: ' , $sheetName , PHP_EOL;
echo 'Worksheet: ' , $sheetName , EOL;
$chartNames = $worksheet->getChartNames();
if(empty($chartNames)) {
echo ' There are no charts in this worksheet' , PHP_EOL;
echo ' There are no charts in this worksheet' , EOL;
} else {
natsort($chartNames);
foreach($chartNames as $i => $chartName) {
@ -80,12 +85,12 @@ foreach($inputFileNames as $inputFileName) {
} else {
$caption = 'Untitled';
}
echo ' ' , $chartName , ' - ' , $caption , PHP_EOL;
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 , PHP_EOL;
echo ' ' , $chartType , EOL;
} else {
$chartTypes = array();
for($i = 0; $i < $groupCount; ++$i) {
@ -94,11 +99,11 @@ foreach($inputFileNames as $inputFileName) {
$chartTypes = array_unique($chartTypes);
if (count($chartTypes) == 1) {
$chartType = 'Multiple Plot ' . array_pop($chartTypes);
echo ' ' , $chartType , PHP_EOL;
echo ' ' , $chartType , EOL;
} elseif (count($chartTypes) == 0) {
echo ' *** Type not yet implemented' , PHP_EOL;
echo ' *** Type not yet implemented' , EOL;
} else {
echo ' Combination Chart' , PHP_EOL;
echo ' Combination Chart' , EOL;
}
}
}
@ -108,18 +113,19 @@ foreach($inputFileNames as $inputFileName) {
$outputFileName = basename($inputFileName);
echo date('H:i:s') , " Write Tests to Excel2007 file " , PHP_EOL;
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 , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing files" , EOL;
echo 'Files have been created in ' , getcwd() , EOL;

View File

@ -2,6 +2,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -127,15 +132,16 @@ $objWorksheet->addChart($chart);
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -2,6 +2,11 @@
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
@ -38,16 +43,16 @@ set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');
include 'PHPExcel.php';
if (!file_exists("33chartcreate.xlsx")) {
exit("Please run 33chartcreate.php first." . PHP_EOL);
exit("Please run 33chartcreate.php first." . EOL);
}
echo date('H:i:s') , " Load from Excel2007 file" , PHP_EOL;
echo date('H:i:s') , " Load from Excel2007 file" , EOL;
$objReader = PHPExcel_IOFactory::createReader("Excel2007");
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load("33chartcreate.xlsx");
echo date('H:i:s') , " Update cell data values that are displayed in the chart" , PHP_EOL;
echo date('H:i:s') , " Update cell data values that are displayed in the chart" , EOL;
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->fromArray(
array(
@ -61,15 +66,16 @@ $objWorksheet->fromArray(
);
// Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , PHP_EOL;
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', __FILE__) , PHP_EOL;
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" , PHP_EOL;
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" , PHP_EOL;
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;