29 error_reporting(E_ALL);
30 ini_set(
'display_errors', TRUE);
31 ini_set(
'display_startup_errors', TRUE);
32 date_default_timezone_set(
'Europe/London');
34 define(
'EOL',(PHP_SAPI ==
'cli') ?
PHP_EOL :
'<br />');
36 date_default_timezone_set(
'Europe/London');
40 require_once dirname(__FILE__) .
'/../Classes/PHPExcel.php';
44 echo
date(
'H:i:s') ,
" List implemented functions" ,
EOL;
46 print_r(
$objCalc->listFunctionNames());
49 echo
date(
'H:i:s') ,
" Create new PHPExcel object" ,
EOL;
53 echo
date(
'H:i:s') ,
" Add some data and formulas" ,
EOL;
54 $objPHPExcel->getActiveSheet()->setCellValue(
'A14',
'Count:')
55 ->setCellValue(
'A15',
'Sum:')
56 ->setCellValue(
'A16',
'Max:')
57 ->setCellValue(
'A17',
'Min:')
58 ->setCellValue(
'A18',
'Average:')
59 ->setCellValue(
'A19',
'Median:')
60 ->setCellValue(
'A20',
'Mode:');
62 $objPHPExcel->getActiveSheet()->setCellValue(
'A22',
'CountA:')
63 ->setCellValue(
'A23',
'MaxA:')
64 ->setCellValue(
'A24',
'MinA:');
66 $objPHPExcel->getActiveSheet()->setCellValue(
'A26',
'StDev:')
67 ->setCellValue(
'A27',
'StDevA:')
68 ->setCellValue(
'A28',
'StDevP:')
69 ->setCellValue(
'A29',
'StDevPA:');
71 $objPHPExcel->getActiveSheet()->setCellValue(
'A31',
'DevSq:')
72 ->setCellValue(
'A32',
'Var:')
73 ->setCellValue(
'A33',
'VarA:')
74 ->setCellValue(
'A34',
'VarP:')
75 ->setCellValue(
'A35',
'VarPA:');
77 $objPHPExcel->getActiveSheet()->setCellValue(
'A37',
'Date:');
80 $objPHPExcel->getActiveSheet()->setCellValue(
'B1',
'Range 1')
81 ->setCellValue(
'B2', 2)
82 ->setCellValue(
'B3', 8)
83 ->setCellValue(
'B4', 10)
84 ->setCellValue(
'B5', True)
85 ->setCellValue(
'B6', False)
86 ->setCellValue(
'B7',
'Text String')
87 ->setCellValue(
'B9',
'22')
88 ->setCellValue(
'B10', 4)
89 ->setCellValue(
'B11', 6)
90 ->setCellValue(
'B12', 12);
92 $objPHPExcel->getActiveSheet()->setCellValue(
'B14',
'=COUNT(B2:B12)')
93 ->setCellValue(
'B15',
'=SUM(B2:B12)')
94 ->setCellValue(
'B16',
'=MAX(B2:B12)')
95 ->setCellValue(
'B17',
'=MIN(B2:B12)')
96 ->setCellValue(
'B18',
'=AVERAGE(B2:B12)')
97 ->setCellValue(
'B19',
'=MEDIAN(B2:B12)')
98 ->setCellValue(
'B20',
'=MODE(B2:B12)');
100 $objPHPExcel->getActiveSheet()->setCellValue(
'B22',
'=COUNTA(B2:B12)')
101 ->setCellValue(
'B23',
'=MAXA(B2:B12)')
102 ->setCellValue(
'B24',
'=MINA(B2:B12)');
104 $objPHPExcel->getActiveSheet()->setCellValue(
'B26',
'=STDEV(B2:B12)')
105 ->setCellValue(
'B27',
'=STDEVA(B2:B12)')
106 ->setCellValue(
'B28',
'=STDEVP(B2:B12)')
107 ->setCellValue(
'B29',
'=STDEVPA(B2:B12)');
109 $objPHPExcel->getActiveSheet()->setCellValue(
'B31',
'=DEVSQ(B2:B12)')
110 ->setCellValue(
'B32',
'=VAR(B2:B12)')
111 ->setCellValue(
'B33',
'=VARA(B2:B12)')
112 ->setCellValue(
'B34',
'=VARP(B2:B12)')
113 ->setCellValue(
'B35',
'=VARPA(B2:B12)');
115 $objPHPExcel->getActiveSheet()->setCellValue(
'B37',
'=DATE(2007, 12, 21)')
116 ->setCellValue(
'B38',
'=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )')
117 ->setCellValue(
'B39',
'=DATEVALUE("01-Feb-2006 10:06 AM")')
118 ->setCellValue(
'B40',
'=DAY( DATE(2006, 1, 2) )')
119 ->setCellValue(
'B41',
'=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )');
122 $objPHPExcel->getActiveSheet()->setCellValue(
'C1',
'Range 2')
123 ->setCellValue(
'C2', 1)
124 ->setCellValue(
'C3', 2)
125 ->setCellValue(
'C4', 2)
126 ->setCellValue(
'C5', 3)
127 ->setCellValue(
'C6', 3)
128 ->setCellValue(
'C7', 3)
129 ->setCellValue(
'C8',
'0')
130 ->setCellValue(
'C9', 4)
131 ->setCellValue(
'C10', 4)
132 ->setCellValue(
'C11', 4)
133 ->setCellValue(
'C12', 4);
135 $objPHPExcel->getActiveSheet()->setCellValue(
'C14',
'=COUNT(C2:C12)')
136 ->setCellValue(
'C15',
'=SUM(C2:C12)')
137 ->setCellValue(
'C16',
'=MAX(C2:C12)')
138 ->setCellValue(
'C17',
'=MIN(C2:C12)')
139 ->setCellValue(
'C18',
'=AVERAGE(C2:C12)')
140 ->setCellValue(
'C19',
'=MEDIAN(C2:C12)')
141 ->setCellValue(
'C20',
'=MODE(C2:C12)');
143 $objPHPExcel->getActiveSheet()->setCellValue(
'C22',
'=COUNTA(C2:C12)')
144 ->setCellValue(
'C23',
'=MAXA(C2:C12)')
145 ->setCellValue(
'C24',
'=MINA(C2:C12)');
147 $objPHPExcel->getActiveSheet()->setCellValue(
'C26',
'=STDEV(C2:C12)')
148 ->setCellValue(
'C27',
'=STDEVA(C2:C12)')
149 ->setCellValue(
'C28',
'=STDEVP(C2:C12)')
150 ->setCellValue(
'C29',
'=STDEVPA(C2:C12)');
152 $objPHPExcel->getActiveSheet()->setCellValue(
'C31',
'=DEVSQ(C2:C12)')
153 ->setCellValue(
'C32',
'=VAR(C2:C12)')
154 ->setCellValue(
'C33',
'=VARA(C2:C12)')
155 ->setCellValue(
'C34',
'=VARP(C2:C12)')
156 ->setCellValue(
'C35',
'=VARPA(C2:C12)');
159 $objPHPExcel->getActiveSheet()->setCellValue(
'D1',
'Range 3')
160 ->setCellValue(
'D2', 2)
161 ->setCellValue(
'D3', 3)
162 ->setCellValue(
'D4', 4);
164 $objPHPExcel->getActiveSheet()->setCellValue(
'D14',
'=((D2 * D3) + D4) & " should be 10"');
166 $objPHPExcel->getActiveSheet()->setCellValue(
'E12',
'Other functions')
167 ->setCellValue(
'E14',
'=PI()')
168 ->setCellValue(
'E15',
'=RAND()')
169 ->setCellValue(
'E16',
'=RANDBETWEEN(5, 10)');
171 $objPHPExcel->getActiveSheet()->setCellValue(
'E17',
'Count of both ranges:')
172 ->setCellValue(
'F17',
'=COUNT(B2:C12)');
174 $objPHPExcel->getActiveSheet()->setCellValue(
'E18',
'Total of both ranges:')
175 ->setCellValue(
'F18',
'=SUM(B2:C12)');
177 $objPHPExcel->getActiveSheet()->setCellValue(
'E19',
'Maximum of both ranges:')
178 ->setCellValue(
'F19',
'=MAX(B2:C12)');
180 $objPHPExcel->getActiveSheet()->setCellValue(
'E20',
'Minimum of both ranges:')
181 ->setCellValue(
'F20',
'=MIN(B2:C12)');
183 $objPHPExcel->getActiveSheet()->setCellValue(
'E21',
'Average of both ranges:')
184 ->setCellValue(
'F21',
'=AVERAGE(B2:C12)');
186 $objPHPExcel->getActiveSheet()->setCellValue(
'E22',
'Median of both ranges:')
187 ->setCellValue(
'F22',
'=MEDIAN(B2:C12)');
189 $objPHPExcel->getActiveSheet()->setCellValue(
'E23',
'Mode of both ranges:')
190 ->setCellValue(
'F23',
'=MODE(B2:C12)');
194 echo
date(
'H:i:s') ,
" Calculated data" ,
EOL;
195 for ($col =
'B'; $col !=
'G'; ++$col) {
197 if ((!is_null($formula =
$objPHPExcel->getActiveSheet()->getCell($col.$row)->getValue())) &&
198 ($formula[0] ==
'=')) {
199 echo
'Value of ' , $col ,
$row ,
' [' , $formula ,
']: ' ,
200 $objPHPExcel->getActiveSheet()->getCell($col.$row)->getCalculatedValue() .
EOL;
207 echo
date(
'H:i:s') ,
" Write to Excel2007 format" ,
EOL;
220 $objWriter->save(str_replace(
'.php',
'.xlsx', __FILE__));
224 echo
date(
'H:i:s') ,
" File written to " , str_replace(
'.php',
'.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) ,
EOL;
225 echo
'Call time to write Workbook was ' , sprintf(
'%.4f',
$callTime) ,
" seconds" ,
EOL;
227 echo
date(
'H:i:s') ,
' Current memory usage: ' , (memory_get_usage(
true) / 1024 / 1024) ,
" MB" , EOL;
231 echo
date(
'H:i:s') ,
" Peak memory usage: " , (memory_get_peak_usage(
true) / 1024 / 1024) ,
" MB" , EOL;
234 echo
date(
'H:i:s') ,
" Done writing file" ,
EOL;
235 echo
'File has been created in ' , getcwd() ,
EOL;
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.