Advertisement
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";
- ;
- }
- }
- }
- function sCellPos($row,$col) //perbaikan
- {
- //hanya untuk A-Z (26)
- //$p=ord('A');//65
- $colInt=64+$col;
- $p=chr($colInt).$row;
- return $p;
- }
- /**
- ##INFO##
- {"title":"excel Dasar ","detail":"Membuat excel menggunakan PHP Spreadsheet . Memanfaatkan excel yang sudah dibuat sebelumnya dan menambahkan isinya. "}
- ##INFO##
- **/
- $filename=__DIR__ . '/../contoh002-a.xlsx';
- $spreadsheet = IOFactory::load($filename);
- if(true)
- {
- $sheet=$spreadsheet->setActiveSheetIndex(0);
- $kalimat=date("Y m d H i s");
- $dates = explode(" ",$kalimat);
- $pos=1;
- foreach($dates as $str)
- {
- $spreadsheet->setActiveSheetIndex(0)->setCellValue(sCellPos(5,$pos++), $str);
- }
- }
- /*
- Pada Bagian ini disarankan simpan ke folder dahulu
- sebelum mengeluarkan..
- atau di download
- */
- $file='test009.xlsx';
- $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
- $writer->save($file);
- 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();
- $str=file_get_contents($file);
- die($str);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement