Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- /*
- Bagian ini silahkan anggap tidak ada..
- karena dasarnya ini include composer (autoload.php)
- */
- {
- $paths = [
- __DIR__ . '/../vendor/autoload.php', // In case PhpSpreadsheet is cloned directly
- __DIR__ . '/../../../autoload.php', // In case PhpSpreadsheet is a composer dependency.
- __DIR__ . '/../../../web/example/vendor/autoload.php' //memakai ini
- ];
- foreach ($paths as $path) {
- if (file_exists($path)) {
- require_once $path;
- //echo "run:$path";
- ;
- }
- }
- }
- /*
- Metode yang disarankan adalah generate HTML dahulu..
- Lalu memakai HTML tersebut sebagai template..
- */
- $html = __DIR__ . '/../_tmp/test.html';
- $callStartTime = microtime(true);
- $objReader = IOFactory::createReader('Html');
- $objPHPExcel = $objReader->load($html);
- /**
- ##INFO##
- {"title":"excel Dasar ","detail":"Membuat excel menggunakan PHP Spreadsheet . Memanfaatkan HTML yang dirubah menjadi excel. "}
- ##INFO##
- **/
- /*
- Pada Bagian ini disarankan simpan ke folder dahulu
- sebelum mengeluarkan..
- atau di download
- */
- $file='contoh007.xlsx';
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment;filename="'.$file.'"');
- header('Content-Length: ' . filesize($file));
- header('Content-Transfer-Encoding: binary');
- header('Cache-Control: must-revalidate');
- header('Pragma: public');
- ob_clean();
- flush();
- $writer = IOFactory::createWriter($objPHPExcel, 'Xlsx');
- $writer->save($file);
- $str=file_get_contents($file);
- die($str);
Add Comment
Please, Sign In to add comment