Advertisement
kura2yamato

excel 008 baca XLSX

May 31st, 2021
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 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. $callStartTime = microtime(true);
  29.  
  30. $inputFileName = __DIR__ . '/../contoh002.xlsx';
  31. $spreadsheet = IOFactory::load($inputFileName);
  32. $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
  33.  
  34. echo '<pre>';
  35. print_r($sheetData);
  36. echo '</pre>';
  37.  
  38. /**
  39. ##INFO##
  40. {"title":"excel Dasar ","detail":"Membaca excel menggunakan PHP Spreadsheet . Menampilkan isinya. <br>dari contoh ini, kita bisa explore lebih lanjut"}
  41. ##INFO##
  42. **/
  43.  
  44.    
  45. /*
  46. Pada Bagian ini disarankan simpan ke folder dahulu
  47. sebelum mengeluarkan..
  48. atau di download
  49.  
  50. $file='contoh007.xlsx';
  51.  
  52. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  53. header('Content-Disposition: attachment;filename="'.$file.'"');
  54. header('Content-Length: ' . filesize($file));
  55.  
  56. header('Content-Transfer-Encoding: binary');
  57. header('Cache-Control: must-revalidate');
  58. header('Pragma: public');
  59.  
  60. ob_clean();
  61. flush();
  62.  
  63. $writer = IOFactory::createWriter($objPHPExcel, 'Xlsx');
  64. $writer->save($file);
  65.  
  66. $str=file_get_contents($file);
  67.  
  68. die($str);
  69. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement