PHPSpreadsheet contoh sederhana

PhpSpreadsheet

Sebelumnya sudah di jelaskan cara untuk instal phpspreadsheet. Berikutnya adalah contoh sederhana phpspreadsheet untuk mengeksport ke dalam file excel. buatkan file index.php.

phpspreadsheet-contoh-00

dan isikan kode script berikut.

<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');

jika kita panggil di browser kode diatas, maka akan muncul hasil file hello world.xlsx seperti dibawah.

phpspreadsheet-contoh-01

phpspreadsheet-contoh-02

Semoga bermanfaat, wassalam.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s