kura2yamato

laravel php spreadsheet 1

Jul 25th, 2021
1,280
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*     
  3.         https://phpspreadsheet.readthedocs.io/en/latest/#hello-world
  4. */
  5.         // require 'vendor/autoload.php';
  6.         // -> tidak perlu karena automatis dari laravel
  7.        
  8.         // use PhpOffice\PhpSpreadsheet\Spreadsheet;
  9.         // use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  10.         // langsung dijalankan di coding bawah
  11.  
  12.         // $spreadsheet = new Spreadsheet();
  13.         $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  14.        
  15.        
  16.         $sheet = $spreadsheet->getActiveSheet();
  17.         $sheet->setCellValue('A1', 'Hello World ! This is Laravel Excel');
  18.  
  19.         // $writer = new Xlsx($spreadsheet);
  20.         $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  21.        
  22.         $writer->save('hello.xlsx');
  23.         //menulis
  24.        
  25.         //dikeluarkan
  26.         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  27.         header('Content-Disposition: attachment;filename="01simple.xlsx"');
  28.         header('Cache-Control: max-age=0');
  29.         // If you're serving to IE 9, then the following may be needed
  30.         header('Cache-Control: max-age=1');
  31.  
  32.         // If you're serving to IE over SSL, then the following may be needed
  33.         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  34.         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  35.         header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  36.         header('Pragma: public'); // HTTP/1.0
  37.         $file = file_get_contents('hello.xlsx');
  38.         print $file;
RAW Paste Data