kura2yamato

Excel 007 create HTML

May 31st, 2021 (edited)
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. use PhpOffice\PhpSpreadsheet\IOFactory;
  4. /*
  5. Bagian ini silahkan anggap tidak ada..
  6. karena dasarnya ini include composer (autoload.php)
  7. */
  8. {
  9.     $paths = [
  10.         __DIR__ . '/../vendor/autoload.php', // In case PhpSpreadsheet is cloned directly
  11.         __DIR__ . '/../../../autoload.php', // In case PhpSpreadsheet is a composer dependency.
  12.         __DIR__ . '/../../../web/example/vendor/autoload.php' //memakai ini
  13.     ];
  14.  
  15.     foreach ($paths as $path) {
  16.         if (file_exists($path)) {
  17.             require_once $path;
  18.             //echo "run:$path";
  19.             ;
  20.         }
  21.     }
  22.  
  23.  
  24.    
  25. }
  26.  
  27. /*
  28. Metode yang disarankan adalah generate HTML dahulu..
  29. Lalu memakai HTML tersebut sebagai template..
  30. */
  31. $html = __DIR__ . '/../_tmp/test.html';
  32. $callStartTime = microtime(true);
  33.  
  34. $objReader = IOFactory::createReader('Html');
  35. $objPHPExcel = $objReader->load($html);
  36.  
  37. /**
  38. ##INFO##
  39. {"title":"excel Dasar ","detail":"Membuat excel menggunakan PHP Spreadsheet . Memanfaatkan HTML yang dirubah menjadi excel. "}
  40. ##INFO##
  41. **/
  42.    
  43. /*
  44. Pada Bagian ini disarankan simpan ke folder dahulu
  45. sebelum mengeluarkan..
  46. atau di download
  47. */
  48. $file='contoh007.xlsx';
  49.  
  50. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  51. header('Content-Disposition: attachment;filename="'.$file.'"');
  52. header('Content-Length: ' . filesize($file));
  53.  
  54. header('Content-Transfer-Encoding: binary');
  55. header('Cache-Control: must-revalidate');
  56. header('Pragma: public');
  57.  
  58. ob_clean();
  59. flush();
  60.  
  61. $writer = IOFactory::createWriter($objPHPExcel, 'Xlsx');
  62. $writer->save($file);
  63.  
  64. $str=file_get_contents($file);
  65.  
  66. die($str);
  67.  
Add Comment
Please, Sign In to add comment