/** * * {@inheritDoc} * * @see \SK\ITCBundle\Service\Table\Adapter\IAdapter::write() */ public function write(Table $table, OutputInterface $output) { $this->getSpreadsheet()->getProperties()->setTitle($table->getTitle())->setDescription($table->getDescription()); $this->writeHeaders($table->getHeaders()); $this->writeRows($table->getRows()); $writer = IOFactory::createWriter($this->getSpreadsheet(), 'CSV'); $writer->save('php://output'); }
echo 'Call time to read Mergebook1 was ', sprintf('%.4f', $callTime), " seconds", EOL; // Echo memory usage echo date('H:i:s'), ' Current memory usage: ', memory_get_usage(true) / 1024 / 1024, " MB", EOL; echo date('H:i:s'), " Load MergeBook2 from Excel2007 file", EOL; $callStartTime = microtime(true); $objPHPExcel2 = \PHPExcel\IOFactory::load(dirname(__FILE__) . "/templates/43mergeBook2.xlsx"); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo 'Call time to read Mergebook2 was ', sprintf('%.4f', $callTime), " seconds", EOL; // Echo memory usage echo date('H:i:s'), ' Current memory usage: ', memory_get_usage(true) / 1024 / 1024, " MB", EOL; foreach ($objPHPExcel2->getSheetNames() as $sheetName) { $sheet = $objPHPExcel2->getSheetByName($sheetName); $sheet->setTitle($sheet->getTitle() . ' copied'); $objPHPExcel1->addExternalSheet($sheet); } echo date('H:i:s'), " Write to Excel2007 format", EOL; $callStartTime = microtime(true); $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel1, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; echo 'Call time to write 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", EOL; // Echo memory peak usage 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", EOL; echo 'File has been created in ', getcwd(), EOL;
if (isset($argc) && $argc > 1) { $inputFileNames = array(); for ($i = 1; $i < $argc; ++$i) { $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); } foreach ($inputFileNames as $inputFileName) { $inputFileNameShort = basename($inputFileName); if (!file_exists($inputFileName)) { echo date('H:i:s'), " File ", $inputFileNameShort, ' does not exist', EOL; continue; } 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", EOL; foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $sheetName = $worksheet->getTitle(); echo 'Worksheet: ', $sheetName, EOL; $chartNames = $worksheet->getChartNames(); if (empty($chartNames)) { echo ' There are no charts in this worksheet', EOL; } else { natsort($chartNames); foreach ($chartNames as $i => $chartName) { $chart = $worksheet->getChartByName($chartName); if (!is_null($chart->getTitle())) { $caption = '"' . implode(' ', $chart->getTitle()->getCaption()) . '"';
/** * @return mixed */ public function output() { $this->getHeader(); $this->getBody(); $objWriter = IOFactory::createWriter($this->workbook, 'Excel5'); $filepath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(uniqid()) . '.xls'; $objWriter->save($filepath); return file_get_contents($filepath); }
// row, but that's not a best practise... $objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension()); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Save Excel 2007 file echo date('H:i:s'), " Write to Excel2007 format", EOL; $callStartTime = microtime(true); $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; echo 'Call time to write 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", EOL; // Save Excel 95 file echo date('H:i:s'), " Write to Excel5 format", EOL; $callStartTime = microtime(true); $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s'), " File written to ", str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; echo 'Call time to write 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", EOL; // Echo memory peak usage 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' . EOL; echo 'Files have been created in ', getcwd(), EOL;
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ /** 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'); /** Include PHPExcel */ require_once dirname(__FILE__) . '/../src/Bootstrap.php'; if (!file_exists("05featuredemo.xlsx")) { exit("Please run 05featuredemo.php first." . 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", EOL; foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { echo 'Worksheet - ', $worksheet->getTitle(), EOL; foreach ($worksheet->getRowIterator() as $row) { 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(), EOL; } } }
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; // Create new PHPExcel object $objPHPExcel = new \PHPExcel\Spreadsheet(); // Set document properties $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2007 XLSX Test Document")->setSubject("Office 2007 XLSX Test Document")->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")->setKeywords("office 2007 openxml php")->setCategory("Test result file"); // Add some data $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Hello')->setCellValue('B2', 'world!')->setCellValue('C1', 'Hello')->setCellValue('D2', 'world!'); // Miscellaneous glyphs, UTF-8 $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A4', 'Miscellaneous glyphs')->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Simple'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (OpenDocument) header('Content-Type: application/vnd.oasis.opendocument.spreadsheet'); header('Content-Disposition: attachment;filename="01simple.ods"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 $objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'OpenDocument'); $objWriter->save('php://output'); exit;
// Rename worksheet echo date('H:i:s'), " Rename worksheet", EOL; $objPHPExcel->getActiveSheet()->setTitle('Datatypes'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Save Excel 95 file echo date('H:i:s'), " Write to Excel5 format", EOL; $callStartTime = microtime(true); $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', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; echo 'Call time to write 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", EOL; echo date('H:i:s'), " Reload workbook from saved file", EOL; $callStartTime = microtime(true); $objPHPExcel = \PHPExcel\IOFactory::load(str_replace('.php', '.xls', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo 'Call time to reload 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", EOL; var_dump($objPHPExcel->getActiveSheet()->toArray()); // Echo memory peak usage 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 testing file", EOL; echo 'File has been created in ', getcwd(), EOL;
</tr> </table> <input name="submit" type="submit" value="calculate"><br /> If A=0, the equation is not quadratic. </form> <?php /** If the user has submitted the form, then we need to execute a calculation **/ if (isset($_POST['submit'])) { if ($_POST['A'] == 0) { echo 'The equation is not quadratic'; } else { /** So we include PHPExcel to perform the calculations **/ include 'PHPExcel/IOFactory.php'; /** Load the quadratic equation solver worksheet into memory **/ $objPHPExcel = \PHPExcel\IOFactory::load('./Quadratic.xlsx'); /** Set our A, B and C values **/ $objPHPExcel->getActiveSheet()->setCellValue('A1', $_POST['A']); $objPHPExcel->getActiveSheet()->setCellValue('B1', $_POST['B']); $objPHPExcel->getActiveSheet()->setCellValue('C1', $_POST['C']); /** Calculate and Display the results **/ echo '<hr /><b>Roots:</b><br />'; $callStartTime = microtime(true); echo $objPHPExcel->getActiveSheet()->getCell('B5')->getCalculatedValue() . '<br />'; echo $objPHPExcel->getActiveSheet()->getCell('B6')->getCalculatedValue() . '<br />'; $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo '<hr />Call time for Quadratic Equation Solution was ' . sprintf('%.4f', $callTime) . ' seconds<br /><hr />'; echo ' Peak memory usage: ' . memory_get_peak_usage(true) / 1024 / 1024 . ' MB<br />'; } }
$callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo 'Call time to reload 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", EOL; echo date('H:i:s'), " Write to Excel2007 format", EOL; $callStartTime = microtime(true); $objWriter2007 = \PHPExcel\IOFactory::createWriter($objPHPExcelFromCSV, 'Excel2007'); $objWriter2007->save(str_replace('.php', '.xlsx', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s'), " File written to ", str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; echo 'Call time to write 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", EOL; echo date('H:i:s'), " Write to CSV format", EOL; $callStartTime = microtime(true); $objWriterCSV = \PHPExcel\IOFactory::createWriter($objPHPExcelFromCSV, 'CSV'); $objWriterCSV->setExcelCompatibility(true); $objWriterCSV->save(str_replace('.php', '_excel.csv', __FILE__)); $callEndTime = microtime(true); $callTime = $callEndTime - $callStartTime; echo date('H:i:s'), " File written to ", str_replace('.php', '_excel.csv', pathinfo(__FILE__, PATHINFO_BASENAME)), EOL; echo 'Call time to write 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", EOL; // Echo memory peak usage 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", EOL; echo 'Files have been created in ', getcwd(), EOL;