PHP code example of remember / laravel-spreadsheet
1. Go to this page and download the library: Download remember/laravel-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/ */
remember / laravel-spreadsheet example snippets
php >7.1
Laravel 6.*
phpoffice/phpspreadsheet ^1.11
/*
* You can place your custom package configuration in here.
*/
return [
'startRow' => 2,
'startLine' => 1,
//Generate the cell format
'columns' => [
//demo
// 'student' => [
// 'fileName' => 'demo123'.time(),
// 'title' => 'demo1',
// 'lineName' => [
// 'name', 'age', 'address',
// ],
//
// ],
],
'style' => [
'format' => [
//Default horizontal vertical center
'alignment' => [
/**
* you can set: left、right、 center、 centerContinuous、 justify、 fill
*/
'horizontal' => 'center',
'vertical' => 'center',
],
],
//default cell width
'width' => 15,
'extra-width' => [
'A' => 20,
'B' => 25,
],
//style cell border
'border' => [
'A1:B1' => [
'borders' => [
'outline' => [
// Border style
// borderStyle you can set:
// dashDot dashDotDot dashed dotted double hair medium';
// 'mediumDashDot mediumDashDotDot mediumDashed slantDashDot thick thin';
'borderStyle' => 'thick',
'color' => ['argb' => 'FFFF0000'],
],
],
],
]
],
];
$data = [
['wuqinqiang', 23, 'HangZhou'],
['curry', 25, 'ShangHai'],
['Tom', 30, 'ShenZhen']
];
app('laravel-phpSpreadsheet')->downloadFile('student', $data);
$path=app('laravel-phpSpreadsheet')->saveFile('student', $data);
return $path;
$data = [
['name'=>'wuqinqiang', 'age'=>24, 'address'=>'QuZhou'],
['name'=>'zhangsan', 'age'=>26, 'address'=>'HangZhou',],
['name'=>'lisi', 'age'=>30, 'address'=>'ShenZhen'],
];
$phpSpreadsheet=app('laravel-phpSpreadsheet');
$sheet= $phpSpreadsheet->init('student');
$sheet = app('laravel-phpSpreadsheet')->init('student');
$count=3;
collect($data)->map(function ($res) use ($sheet, &$count) {
$sheet->setCellValue('A' . $count, $res['name']);
$sheet->setCellValue('B' . $count, $res['age']);
$sheet->setCellValue('C' . $count, $res['address']);
$count++;
});
// save file
$file= $phpSpreadsheet->saveLocal('student');
// download
$phpSpreadsheet->downForBrowser('student');
bash
php artisan vendor:publish --provider="Remember\LaravelPhpSpreadsheet\LaravelPhpSpreadsheetServiceProvider"