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

This commit is contained in:
Mark Baker 2012-08-05 22:06:51 +01:00
parent 8ba160ed28
commit 0588576fe2
6 changed files with 194 additions and 158 deletions

View File

@ -27,6 +27,11 @@
/** Error reporting */ /** Error reporting */
error_reporting(E_ALL); 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'); date_default_timezone_set('Europe/London');
@ -35,177 +40,178 @@ require_once '../Classes/PHPExcel.php';
// List functions // List functions
echo date('H:i:s') , " List implemented functions" , PHP_EOL; echo date('H:i:s') , " List implemented functions" , EOL;
$objCalc = PHPExcel_Calculation::getInstance(); $objCalc = PHPExcel_Calculation::getInstance();
print_r($objCalc->listFunctionNames()); print_r($objCalc->listFunctionNames());
// Create new PHPExcel object // 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(); $objPHPExcel = new PHPExcel();
// Add some data, we will use some formulas here // Add some data, we will use some formulas here
echo date('H:i:s') , " Add some data and formulas" , PHP_EOL; echo date('H:i:s') , " Add some data and formulas" , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A14', 'Count:'); $objPHPExcel->getActiveSheet()->setCellValue('A14', 'Count:')
$objPHPExcel->getActiveSheet()->setCellValue('A15', 'Sum:'); ->setCellValue('A15', 'Sum:')
$objPHPExcel->getActiveSheet()->setCellValue('A16', 'Max:'); ->setCellValue('A16', 'Max:')
$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Min:'); ->setCellValue('A17', 'Min:')
$objPHPExcel->getActiveSheet()->setCellValue('A18', 'Average:'); ->setCellValue('A18', 'Average:')
$objPHPExcel->getActiveSheet()->setCellValue('A19', 'Median:'); ->setCellValue('A19', 'Median:')
$objPHPExcel->getActiveSheet()->setCellValue('A20', 'Mode:'); ->setCellValue('A20', 'Mode:');
$objPHPExcel->getActiveSheet()->setCellValue('A22', 'CountA:'); $objPHPExcel->getActiveSheet()->setCellValue('A22', 'CountA:')
$objPHPExcel->getActiveSheet()->setCellValue('A23', 'MaxA:'); ->setCellValue('A23', 'MaxA:')
$objPHPExcel->getActiveSheet()->setCellValue('A24', 'MinA:'); ->setCellValue('A24', 'MinA:');
$objPHPExcel->getActiveSheet()->setCellValue('A26', 'StDev:'); $objPHPExcel->getActiveSheet()->setCellValue('A26', 'StDev:')
$objPHPExcel->getActiveSheet()->setCellValue('A27', 'StDevA:'); ->setCellValue('A27', 'StDevA:')
$objPHPExcel->getActiveSheet()->setCellValue('A28', 'StDevP:'); ->setCellValue('A28', 'StDevP:')
$objPHPExcel->getActiveSheet()->setCellValue('A29', 'StDevPA:'); ->setCellValue('A29', 'StDevPA:');
$objPHPExcel->getActiveSheet()->setCellValue('A31', 'DevSq:'); $objPHPExcel->getActiveSheet()->setCellValue('A31', 'DevSq:')
$objPHPExcel->getActiveSheet()->setCellValue('A32', 'Var:'); ->setCellValue('A32', 'Var:')
$objPHPExcel->getActiveSheet()->setCellValue('A33', 'VarA:'); ->setCellValue('A33', 'VarA:')
$objPHPExcel->getActiveSheet()->setCellValue('A34', 'VarP:'); ->setCellValue('A34', 'VarP:')
$objPHPExcel->getActiveSheet()->setCellValue('A35', 'VarPA:'); ->setCellValue('A35', 'VarPA:');
$objPHPExcel->getActiveSheet()->setCellValue('A37', 'Date:'); $objPHPExcel->getActiveSheet()->setCellValue('A37', 'Date:');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range 1'); $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range 1')
$objPHPExcel->getActiveSheet()->setCellValue('B2', 2); ->setCellValue('B2', 2)
$objPHPExcel->getActiveSheet()->setCellValue('B3', 8); ->setCellValue('B3', 8)
$objPHPExcel->getActiveSheet()->setCellValue('B4', 10); ->setCellValue('B4', 10)
$objPHPExcel->getActiveSheet()->setCellValue('B5', True); ->setCellValue('B5', True)
$objPHPExcel->getActiveSheet()->setCellValue('B6', False); ->setCellValue('B6', False)
$objPHPExcel->getActiveSheet()->setCellValue('B7', 'Text String'); ->setCellValue('B7', 'Text String')
$objPHPExcel->getActiveSheet()->setCellValue('B9', '22'); ->setCellValue('B9', '22')
$objPHPExcel->getActiveSheet()->setCellValue('B10', 4); ->setCellValue('B10', 4)
$objPHPExcel->getActiveSheet()->setCellValue('B11', 6); ->setCellValue('B11', 6)
$objPHPExcel->getActiveSheet()->setCellValue('B12', 12); ->setCellValue('B12', 12);
$objPHPExcel->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)'); $objPHPExcel->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B15', '=SUM(B2:B12)'); ->setCellValue('B15', '=SUM(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B16', '=MAX(B2:B12)'); ->setCellValue('B16', '=MAX(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B17', '=MIN(B2:B12)'); ->setCellValue('B17', '=MIN(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B18', '=AVERAGE(B2:B12)'); ->setCellValue('B18', '=AVERAGE(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B19', '=MEDIAN(B2:B12)'); ->setCellValue('B19', '=MEDIAN(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B20', '=MODE(B2:B12)'); ->setCellValue('B20', '=MODE(B2:B12)');
$objPHPExcel->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)'); $objPHPExcel->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B23', '=MAXA(B2:B12)'); ->setCellValue('B23', '=MAXA(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B24', '=MINA(B2:B12)'); ->setCellValue('B24', '=MINA(B2:B12)');
$objPHPExcel->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)'); $objPHPExcel->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B27', '=STDEVA(B2:B12)'); ->setCellValue('B27', '=STDEVA(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B28', '=STDEVP(B2:B12)'); ->setCellValue('B28', '=STDEVP(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B29', '=STDEVPA(B2:B12)'); ->setCellValue('B29', '=STDEVPA(B2:B12)');
$objPHPExcel->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)'); $objPHPExcel->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B32', '=VAR(B2:B12)'); ->setCellValue('B32', '=VAR(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B33', '=VARA(B2:B12)'); ->setCellValue('B33', '=VARA(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B34', '=VARP(B2:B12)'); ->setCellValue('B34', '=VARP(B2:B12)')
$objPHPExcel->getActiveSheet()->setCellValue('B35', '=VARPA(B2:B12)'); ->setCellValue('B35', '=VARPA(B2:B12)');
$objPHPExcel->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)'); $objPHPExcel->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)')
$objPHPExcel->getActiveSheet()->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )'); ->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )')
$objPHPExcel->getActiveSheet()->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")'); ->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")')
$objPHPExcel->getActiveSheet()->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )'); ->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )')
$objPHPExcel->getActiveSheet()->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )'); ->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range 2'); $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range 2')
$objPHPExcel->getActiveSheet()->setCellValue('C2', 1); ->setCellValue('C2', 1)
$objPHPExcel->getActiveSheet()->setCellValue('C3', 2); ->setCellValue('C3', 2)
$objPHPExcel->getActiveSheet()->setCellValue('C4', 2); ->setCellValue('C4', 2)
$objPHPExcel->getActiveSheet()->setCellValue('C5', 3); ->setCellValue('C5', 3)
$objPHPExcel->getActiveSheet()->setCellValue('C6', 3); ->setCellValue('C6', 3)
$objPHPExcel->getActiveSheet()->setCellValue('C7', 3); ->setCellValue('C7', 3)
$objPHPExcel->getActiveSheet()->setCellValue('C8', '0'); ->setCellValue('C8', '0')
$objPHPExcel->getActiveSheet()->setCellValue('C9', 4); ->setCellValue('C9', 4)
$objPHPExcel->getActiveSheet()->setCellValue('C10', 4); ->setCellValue('C10', 4)
$objPHPExcel->getActiveSheet()->setCellValue('C11', 4); ->setCellValue('C11', 4)
$objPHPExcel->getActiveSheet()->setCellValue('C12', 4); ->setCellValue('C12', 4);
$objPHPExcel->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)'); $objPHPExcel->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C15', '=SUM(C2:C12)'); ->setCellValue('C15', '=SUM(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C16', '=MAX(C2:C12)'); ->setCellValue('C16', '=MAX(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C17', '=MIN(C2:C12)'); ->setCellValue('C17', '=MIN(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C18', '=AVERAGE(C2:C12)'); ->setCellValue('C18', '=AVERAGE(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C19', '=MEDIAN(C2:C12)'); ->setCellValue('C19', '=MEDIAN(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C20', '=MODE(C2:C12)'); ->setCellValue('C20', '=MODE(C2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)'); $objPHPExcel->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C23', '=MAXA(C2:C12)'); ->setCellValue('C23', '=MAXA(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C24', '=MINA(C2:C12)'); ->setCellValue('C24', '=MINA(C2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)'); $objPHPExcel->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C27', '=STDEVA(C2:C12)'); ->setCellValue('C27', '=STDEVA(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C28', '=STDEVP(C2:C12)'); ->setCellValue('C28', '=STDEVP(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C29', '=STDEVPA(C2:C12)'); ->setCellValue('C29', '=STDEVPA(C2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)'); $objPHPExcel->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C32', '=VAR(C2:C12)'); ->setCellValue('C32', '=VAR(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C33', '=VARA(C2:C12)'); ->setCellValue('C33', '=VARA(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C34', '=VARP(C2:C12)'); ->setCellValue('C34', '=VARP(C2:C12)')
$objPHPExcel->getActiveSheet()->setCellValue('C35', '=VARPA(C2:C12)'); ->setCellValue('C35', '=VARPA(C2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Range 3'); $objPHPExcel->getActiveSheet()->setCellValue('D1', 'Range 3')
$objPHPExcel->getActiveSheet()->setCellValue('D2', 2); ->setCellValue('D2', 2)
$objPHPExcel->getActiveSheet()->setCellValue('D3', 3); ->setCellValue('D3', 3)
$objPHPExcel->getActiveSheet()->setCellValue('D4', 4); ->setCellValue('D4', 4);
$objPHPExcel->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"'); $objPHPExcel->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"');
$objPHPExcel->getActiveSheet()->setCellValue('E12', 'Other functions'); $objPHPExcel->getActiveSheet()->setCellValue('E12', 'Other functions')
$objPHPExcel->getActiveSheet()->setCellValue('E14', '=PI()'); ->setCellValue('E14', '=PI()')
$objPHPExcel->getActiveSheet()->setCellValue('E15', '=RAND()'); ->setCellValue('E15', '=RAND()')
$objPHPExcel->getActiveSheet()->setCellValue('E16', '=RANDBETWEEN(5, 10)'); ->setCellValue('E16', '=RANDBETWEEN(5, 10)');
$objPHPExcel->getActiveSheet()->setCellValue('E17', 'Count of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E17', 'Count of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F17', '=COUNT(B2:C12)'); ->setCellValue('F17', '=COUNT(B2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('E18', 'Total of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E18', 'Total of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F18', '=SUM(B2:C12)'); ->setCellValue('F18', '=SUM(B2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F19', '=MAX(B2:C12)'); ->setCellValue('F19', '=MAX(B2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F20', '=MIN(B2:C12)'); ->setCellValue('F20', '=MIN(B2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('E21', 'Average of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E21', 'Average of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F21', '=AVERAGE(B2:C12)'); ->setCellValue('F21', '=AVERAGE(B2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('E22', 'Median of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E22', 'Median of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F22', '=MEDIAN(B2:C12)'); ->setCellValue('F22', '=MEDIAN(B2:C12)');
$objPHPExcel->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:'); $objPHPExcel->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:')
$objPHPExcel->getActiveSheet()->setCellValue('F23', '=MODE(B2:C12)'); ->setCellValue('F23', '=MODE(B2:C12)');
// Calculated data // Calculated data
echo date('H:i:s') , " Calculated data" , PHP_EOL; echo date('H:i:s') , " Calculated data" , EOL;
for ($col = 'B'; $col != 'G'; ++$col) { for ($col = 'B'; $col != 'G'; ++$col) {
for($row = 14; $row <= 41; ++$row) { for($row = 14; $row <= 41; ++$row) {
if ((!is_null($formula = $objPHPExcel->getActiveSheet()->getCell($col.$row)->getValue())) && if ((!is_null($formula = $objPHPExcel->getActiveSheet()->getCell($col.$row)->getValue())) &&
($formula[0] == '=')) { ($formula[0] == '=')) {
echo 'Value of ' , $col , $row , ' [' , $formula , ']: ' , echo 'Value of ' , $col , $row , ' [' , $formula , ']: ' ,
$objPHPExcel->getActiveSheet()->getCell($col.$row)->getCalculatedValue() . PHP_EOL; $objPHPExcel->getActiveSheet()->getCell($col.$row)->getCalculatedValue() . EOL;
} }
} }
} }
// Save Excel 2007 file // 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 = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $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 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 done
echo date('H:i:s') , " Done" , 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 */
error_reporting(E_ALL); 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'); date_default_timezone_set('Europe/London');
@ -36,14 +41,15 @@ include "05featuredemo.inc.php";
require_once '../Classes/PHPExcel/IOFactory.php'; require_once '../Classes/PHPExcel/IOFactory.php';
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 = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__)); $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 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 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,11 @@
/** Error reporting */ /** Error reporting */
error_reporting(E_ALL); 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'); date_default_timezone_set('Europe/London');
@ -35,12 +40,12 @@ require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object // 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(); $objPHPExcel = new PHPExcel();
// Set document properties // 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") $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
@ -51,17 +56,17 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Create a first sheet // Create a first sheet
echo date('H:i:s') , " Add data" , PHP_EOL; echo date('H:i:s') , " Add data" , EOL;
$objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation..."); $objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...")
$objPHPExcel->getActiveSheet()->setCellValue('A3', "Number:"); ->setCellValue('A3', "Number:")
$objPHPExcel->getActiveSheet()->setCellValue('B3', "10"); ->setCellValue('B3', "10")
$objPHPExcel->getActiveSheet()->setCellValue('A5', "List:"); ->setCellValue('A5', "List:")
$objPHPExcel->getActiveSheet()->setCellValue('B5', "Item A"); ->setCellValue('B5', "Item A");
// Set data validation // Set data validation
echo date('H:i:s') , " Set data validation" , PHP_EOL; echo date('H:i:s') , " Set data validation" , EOL;
$objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation(); $objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE ); $objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP ); $objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
@ -94,14 +99,15 @@ $objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file // 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 = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__)); $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 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 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 */
error_reporting(E_ALL); 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'); date_default_timezone_set('Europe/London');
@ -35,12 +40,12 @@ require_once '../Classes/PHPExcel.php';
// Create new PHPExcel object // 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(); $objPHPExcel = new PHPExcel();
// Set document properties // 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") $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
@ -51,17 +56,17 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Create a first sheet // Create a first sheet
echo date('H:i:s') , " Add data" , PHP_EOL; echo date('H:i:s') , " Add data" , EOL;
$objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation..."); $objPHPExcel->getActiveSheet()->setCellValue('A1', "Cell B3 and B5 contain data validation...")
$objPHPExcel->getActiveSheet()->setCellValue('A3', "Number:"); ->setCellValue('A3', "Number:")
$objPHPExcel->getActiveSheet()->setCellValue('B3', "10"); ->setCellValue('B3', "10")
$objPHPExcel->getActiveSheet()->setCellValue('A5', "List:"); ->setCellValue('A5', "List:")
$objPHPExcel->getActiveSheet()->setCellValue('B5', "Item A"); ->setCellValue('B5', "Item A");
// Set data validation // Set data validation
echo date('H:i:s') , " Set data validation" , PHP_EOL; echo date('H:i:s') , " Set data validation" , EOL;
$objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation(); $objValidation = $objPHPExcel->getActiveSheet()->getCell('B3')->getDataValidation();
$objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE ); $objValidation->setType( PHPExcel_Cell_DataValidation::TYPE_WHOLE );
$objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP ); $objValidation->setErrorStyle( PHPExcel_Cell_DataValidation::STYLE_STOP );
@ -94,14 +99,15 @@ $objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file // 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 = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $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 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 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 */
error_reporting(E_ALL); 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'); date_default_timezone_set('Europe/London');
@ -36,31 +41,32 @@ include "05featuredemo.inc.php";
require_once '../Classes/PHPExcel/IOFactory.php'; require_once '../Classes/PHPExcel/IOFactory.php';
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')->setDelimiter(',') $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter(',')
->setEnclosure('"') ->setEnclosure('"')
->setLineEnding("\r\n") ->setLineEnding("\r\n")
->setSheetIndex(0) ->setSheetIndex(0)
->save(str_replace('.php', '.csv', __FILE__)); ->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;
echo date('H:i:s') , " Read from CSV format" , PHP_EOL; echo date('H:i:s') , " Read from CSV format" , EOL;
$objReader = PHPExcel_IOFactory::createReader('CSV')->setDelimiter(',') $objReader = PHPExcel_IOFactory::createReader('CSV')->setDelimiter(',')
->setEnclosure('"') ->setEnclosure('"')
->setLineEnding("\r\n") ->setLineEnding("\r\n")
->setSheetIndex(0); ->setSheetIndex(0);
$objPHPExcelFromCSV = $objReader->load(str_replace('.php', '.csv', __FILE__)); $objPHPExcelFromCSV = $objReader->load(str_replace('.php', '.csv', __FILE__));
echo date('H:i:s') , " File read from " , str_replace('.php', '.csv', __FILE__) , PHP_EOL; echo date('H:i:s') , " File read from " , str_replace('.php', '.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo date('H:i:s') , " Write to Excel2007 format" , PHP_EOL; echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$objWriter2007 = PHPExcel_IOFactory::createWriter($objPHPExcelFromCSV, 'Excel2007'); $objWriter2007 = PHPExcel_IOFactory::createWriter($objPHPExcelFromCSV, 'Excel2007');
$objWriter2007->save(str_replace('.php', '.xlsx', __FILE__)); $objWriter2007->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 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 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,11 @@
/** Error reporting */ /** Error reporting */
error_reporting(E_ALL); 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'); date_default_timezone_set('Europe/London');
@ -36,16 +41,17 @@ include "05featuredemo.inc.php";
require_once '../Classes/PHPExcel/IOFactory.php'; require_once '../Classes/PHPExcel/IOFactory.php';
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 = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->setSheetIndex(0); $objWriter->setSheetIndex(0);
//$objWriter->setImagesRoot('http://www.example.com'); //$objWriter->setImagesRoot('http://www.example.com');
$objWriter->save(str_replace('.php', '.htm', __FILE__)); $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;
// Echo memory peak usage // 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 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;