1. Go to this page and download the library: Download osmaviation/spreadsheet library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use OSMAviation\Spreadsheet\Facades\Spreadsheet;
$filename = 'my-filename.xlsx';
Spreadsheet::create($filename, function ($excel) {
$excel->sheet('Worksheet', function ($sheet) {
$sheet->fromArray([
'Foo',
'Bar',
], null, 'A1', true, false);
});
});
use OSMAviation\Spreadsheet\PhpSpreadsheet as Spreadsheet;
class MyController
{
public function store(Spreadsheet $spreadsheet)
{
$filename = 'my-filename.xlsx';
$spreadsheet->create($filename, function ($excel) {
$excel->sheet('Worksheet', function ($sheet) {
$sheet->fromArray([
'Foo',
'Bar',
], null, 'A1', true, false);
});
});
}
}
$filename = 'some-folder/my-filename.xlsx';
Spreadsheet::create($filename, function ($excel) {
$excel->sheet('Worksheet', function ($sheet) {
// $sheet will be a PhpOffice\PhpSpreadsheet\Worksheet\Worksheet instance
$sheet->fromArray([
'Foo',
'Bar',
], null, 'A1', true, false);
});
})->store('local');