Skip to content

Instantly share code, notes, and snippets.

@erowsika
Created December 7, 2022 02:58
Show Gist options
  • Save erowsika/82b9f07940860574f987caf77e1878ca to your computer and use it in GitHub Desktop.
Save erowsika/82b9f07940860574f987caf77e1878ca to your computer and use it in GitHub Desktop.
spatie/simple-excel example
<?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