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; $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; // Export to Excel5 (.xls) echo date('H:i:s') , " Write to Excel5 format" , PHP_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; // Export to HTML (.html) echo date('H:i:s') , " Write to HTML format" , PHP_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; // Export to PDF (.pdf) echo date('H:i:s') , " Write to PDF format" , PHP_EOL; try { if (!PHPExcel_Settings::setPdfRenderer( $rendererName, $rendererLibraryPath )) { echo ( 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . PHP_EOL . 'at the top of this script as appropriate for your directory structure' ); } 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; } } catch (Exception $e) { echo date('H:i:s') , ' EXCEPTION: ', $e->getMessage() , PHP_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; $objWorksheet = $objPHPExcel->getActiveSheet(); $objWorksheet->removeRow(1, 2); // Export to CSV (.csv) echo date('H:i:s') , " Write to CSV format" , PHP_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; // Export to CSV with BOM (.csv) echo date('H:i:s') , " Write to CSV format (with BOM)" , PHP_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 memory peak usage echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , PHP_EOL; // Echo done echo date('H:i:s') , " Done writing files" , PHP_EOL;