Created
December 7, 2022 02:58
-
-
Save erowsika/82b9f07940860574f987caf77e1878ca to your computer and use it in GitHub Desktop.
spatie/simple-excel example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Spatie\SimpleExcel\SimpleExcelWriter; | |
$username = "blabla"; | |
$pass = "3CVzq8MmV8U3TXDL"; | |
$host = "localhost"; | |
$db = "db_arsip"; | |
$connect = mysqli_connect($host, $username, $pass, $db) or die(mysqli_error($connect)); | |
$populate = mysqli_query($connect, "SELECT * FROM arsip;"); | |
$counter = 0; | |
$writer = SimpleExcelWriter::streamDownload('your-export.xlsx'); | |
while ($row = mysqli_fetch_array($populate)) { | |
$writer->addRow([ | |
// nama_kolom => isi_kolom | |
'no' => $row['no_arsip'], | |
'judul' => $row['judul'], | |
'klasifikasi' => $row['klasifikasi'], | |
]); | |
if ($counter % 1000 === 0) { | |
flush(); // Flush the buffer every 1000 rows | |
} | |
$counter++; | |
} | |
$writer->toBrowser(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment