29 error_reporting(E_ALL);
32 require_once dirname(__FILE__) .
'/../Classes/PHPExcel.php';
36 echo date(
'H:i:s') ,
" Create new PHPExcel object" ,
EOL;
41 $objPHPExcel->getProperties()->setCreator(
"Maarten Balliauw")
42 ->setLastModifiedBy(
"Maarten Balliauw")
43 ->setTitle(
"Office 2007 XLSX Test Document")
44 ->setSubject(
"Office 2007 XLSX Test Document")
45 ->setDescription(
"Test document for Office 2007 XLSX, generated using PHP classes.")
46 ->setKeywords(
"office 2007 openxml php")
47 ->setCategory(
"Test result file");
53 $objPHPExcel->getActiveSheet()->setCellValue(
'B1',
'Invoice');
56 $objPHPExcel->getActiveSheet()->setCellValue(
'E1',
'#12566');
58 $objPHPExcel->getActiveSheet()->setCellValue(
'A3',
'Product Id');
59 $objPHPExcel->getActiveSheet()->setCellValue(
'B3',
'Description');
60 $objPHPExcel->getActiveSheet()->setCellValue(
'C3',
'Price');
61 $objPHPExcel->getActiveSheet()->setCellValue(
'D3',
'Amount');
62 $objPHPExcel->getActiveSheet()->setCellValue(
'E3',
'Total');
64 $objPHPExcel->getActiveSheet()->setCellValue(
'A4',
'1001');
65 $objPHPExcel->getActiveSheet()->setCellValue(
'B4',
'PHP for dummies');
66 $objPHPExcel->getActiveSheet()->setCellValue(
'C4',
'20');
68 $objPHPExcel->getActiveSheet()->setCellValue(
'E4',
'=IF(D4<>"",C4*D4,"")');
70 $objPHPExcel->getActiveSheet()->setCellValue(
'A5',
'1012');
71 $objPHPExcel->getActiveSheet()->setCellValue(
'B5',
'OpenXML for dummies');
72 $objPHPExcel->getActiveSheet()->setCellValue(
'C5',
'22');
74 $objPHPExcel->getActiveSheet()->setCellValue(
'E5',
'=IF(D5<>"",C5*D5,"")');
76 $objPHPExcel->getActiveSheet()->setCellValue(
'E6',
'=IF(D6<>"",C6*D6,"")');
77 $objPHPExcel->getActiveSheet()->setCellValue(
'E7',
'=IF(D7<>"",C7*D7,"")');
78 $objPHPExcel->getActiveSheet()->setCellValue(
'E8',
'=IF(D8<>"",C8*D8,"")');
79 $objPHPExcel->getActiveSheet()->setCellValue(
'E9',
'=IF(D9<>"",C9*D9,"")');
81 $objPHPExcel->getActiveSheet()->setCellValue(
'D11',
'Total excl.:');
82 $objPHPExcel->getActiveSheet()->setCellValue(
'E11',
'=SUM(E4:E9)');
84 $objPHPExcel->getActiveSheet()->setCellValue(
'D12',
'VAT:');
85 $objPHPExcel->getActiveSheet()->setCellValue(
'E12',
'=E11*0.21');
87 $objPHPExcel->getActiveSheet()->setCellValue(
'D13',
'Total incl.:');
88 $objPHPExcel->getActiveSheet()->setCellValue(
'E13',
'=E11+E12');
93 $objPHPExcel->getActiveSheet()->getComment(
'E11')->setAuthor(
'PHPExcel');
96 $objPHPExcel->getActiveSheet()->getComment(
'E11')->getText()->createTextRun(
"\r\n");
97 $objPHPExcel->getActiveSheet()->getComment(
'E11')->getText()->createTextRun(
'Total amount on the current invoice, excluding VAT.');
99 $objPHPExcel->getActiveSheet()->getComment(
'E12')->setAuthor(
'PHPExcel');
102 $objPHPExcel->getActiveSheet()->getComment(
'E12')->getText()->createTextRun(
"\r\n");
103 $objPHPExcel->getActiveSheet()->getComment(
'E12')->getText()->createTextRun(
'Total amount of VAT on the current invoice.');
105 $objPHPExcel->getActiveSheet()->getComment(
'E13')->setAuthor(
'PHPExcel');
108 $objPHPExcel->getActiveSheet()->getComment(
'E13')->getText()->createTextRun(
"\r\n");
109 $objPHPExcel->getActiveSheet()->getComment(
'E13')->getText()->createTextRun(
'Total amount on the current invoice, including VAT.');
110 $objPHPExcel->getActiveSheet()->getComment(
'E13')->setWidth(
'100pt');
111 $objPHPExcel->getActiveSheet()->getComment(
'E13')->setHeight(
'100pt');
112 $objPHPExcel->getActiveSheet()->getComment(
'E13')->setMarginLeft(
'150pt');
113 $objPHPExcel->getActiveSheet()->getComment(
'E13')->getFillColor()->setRGB(
'EEEEEE');
126 $objRichText->createText(
', unless specified otherwise on the invoice.');
134 $objPHPExcel->getActiveSheet()->unmergeCells(
'A28:B28');
138 $objPHPExcel->getActiveSheet()->getProtection()->setSheet(
true);
139 $objPHPExcel->getActiveSheet()->protectCells(
'A3:E13',
'PHPExcel');
147 $objPHPExcel->getActiveSheet()->getColumnDimension(
'B')->setAutoSize(
true);
148 $objPHPExcel->getActiveSheet()->getColumnDimension(
'D')->setWidth(12);
149 $objPHPExcel->getActiveSheet()->getColumnDimension(
'E')->setWidth(12);
153 $objPHPExcel->getActiveSheet()->getStyle(
'B1')->getFont()->setName(
'Candara');
154 $objPHPExcel->getActiveSheet()->getStyle(
'B1')->getFont()->setSize(20);
155 $objPHPExcel->getActiveSheet()->getStyle(
'B1')->getFont()->setBold(
true);
162 $objPHPExcel->getActiveSheet()->getStyle(
'D13')->getFont()->setBold(
true);
163 $objPHPExcel->getActiveSheet()->getStyle(
'E13')->getFont()->setBold(
true);
174 $objPHPExcel->getActiveSheet()->getStyle(
'B5')->getAlignment()->setShrinkToFit(
true);
177 echo date(
'H:i:s') ,
" Set thin black border outline around column" ,
EOL;
182 'color' =>
array(
'argb' =>
'FF000000'),
190 echo date(
'H:i:s') ,
" Set thick brown border outline around Total" ,
EOL;
195 'color' =>
array(
'argb' =>
'FF993300'),
204 $objPHPExcel->getActiveSheet()->getStyle(
'A1:E1')->getFill()->getStartColor()->setARGB(
'FF808080');
207 echo date(
'H:i:s') ,
" Set style for header row using alternative method" ,
EOL;
208 $objPHPExcel->getActiveSheet()->getStyle(
'A3:E3')->applyFromArray(
213 'alignment' =>
array(
224 'startcolor' =>
array(
234 $objPHPExcel->getActiveSheet()->getStyle(
'A3')->applyFromArray(
236 'alignment' =>
array(
247 $objPHPExcel->getActiveSheet()->getStyle(
'B3')->applyFromArray(
249 'alignment' =>
array(
255 $objPHPExcel->getActiveSheet()->getStyle(
'E3')->applyFromArray(
270 echo date(
'H:i:s') ,
" Add a hyperlink to an external website" ,
EOL;
271 $objPHPExcel->getActiveSheet()->setCellValue(
'E26',
'www.phpexcel.net');
272 $objPHPExcel->getActiveSheet()->getCell(
'E26')->getHyperlink()->setUrl(
'http://www.phpexcel.net');
273 $objPHPExcel->getActiveSheet()->getCell(
'E26')->getHyperlink()->setTooltip(
'Navigate to website');
276 echo date(
'H:i:s') ,
" Add a hyperlink to another cell on a different worksheet within the workbook" ,
EOL;
277 $objPHPExcel->getActiveSheet()->setCellValue(
'E27',
'Terms and conditions');
278 $objPHPExcel->getActiveSheet()->getCell(
'E27')->getHyperlink()->setUrl(
"sheet://'Terms and conditions'!A1");
279 $objPHPExcel->getActiveSheet()->getCell(
'E27')->getHyperlink()->setTooltip(
'Review terms and conditions');
292 echo date(
'H:i:s') ,
" Add a drawing to the worksheet" ,
EOL;
305 echo date(
'H:i:s') ,
" Add a drawing to the worksheet" ,
EOL;
309 $objDrawing->setPath(
'./images/phpexcel_logo.gif');
316 echo date(
'H:i:s') ,
" Play around with inserting and removing rows and columns" ,
EOL;
317 $objPHPExcel->getActiveSheet()->insertNewRowBefore(6, 10);
319 $objPHPExcel->getActiveSheet()->insertNewColumnBefore(
'E', 5);
324 $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(
'&L&BInvoice&RPrinted on &D');
325 $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter(
'&L&B' .
$objPHPExcel->getProperties()->getTitle() .
'&RPage &P of &N');
333 echo date(
'H:i:s') ,
" Rename first worksheet" ,
EOL;
338 echo date(
'H:i:s') ,
" Create a second Worksheet object" ,
EOL;
342 $sLloremIpsum =
'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus eget ante. Sed cursus nunc semper tortor. Aliquam luctus purus non elit. Fusce vel elit commodo sapien dignissim dignissim. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Curabitur accumsan magna sed massa. Nullam bibendum quam ac ipsum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin augue. Praesent malesuada justo sed orci. Pellentesque lacus ligula, sodales quis, ultricies a, ultricies vitae, elit. Sed luctus consectetuer dolor. Vivamus vel sem ut nisi sodales accumsan. Nunc et felis. Suspendisse semper viverra odio. Morbi at odio. Integer a orci a purus venenatis molestie. Nam mattis. Praesent rhoncus, nisi vel mattis auctor, neque nisi faucibus sem, non dapibus elit pede ac nisl. Cras turpis.';
347 $objPHPExcel->getActiveSheet()->setCellValue(
'A1',
'Terms and conditions');
355 $objPHPExcel->getActiveSheet()->getTabColor()->setARGB(
'FF0094FF');;
359 $objPHPExcel->getActiveSheet()->getStyle(
'A3:A6')->getAlignment()->setWrapText(
true);
363 $objPHPExcel->getActiveSheet()->getColumnDimension(
'A')->setWidth(80);
367 $objPHPExcel->getActiveSheet()->getStyle(
'A1')->getFont()->setName(
'Candara');
368 $objPHPExcel->getActiveSheet()->getStyle(
'A1')->getFont()->setSize(20);
369 $objPHPExcel->getActiveSheet()->getStyle(
'A1')->getFont()->setBold(
true);
372 $objPHPExcel->getActiveSheet()->getStyle(
'A3:A6')->getFont()->setSize(8);
375 echo date(
'H:i:s') ,
" Add a drawing to the worksheet" ,
EOL;
378 $objDrawing->setDescription(
'Terms and conditions');
379 $objDrawing->setPath(
'./images/termsconditions.jpg');
384 echo date(
'H:i:s') ,
" Set page orientation and size" ,
EOL;
389 echo date(
'H:i:s') ,
" Rename second worksheet" ,
EOL;
390 $objPHPExcel->getActiveSheet()->setTitle(
'Terms and conditions');
$styleThickBrownBorderOutline
const PROTECTION_UNPROTECTED
const ORIENTATION_LANDSCAPE
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
const ORIENTATION_PORTRAIT
$styleThinBlackBorderOutline
static PHPToExcel($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from PHP to Excel.
const FILL_GRADIENT_LINEAR