Last article summarizes the use of VS2005 + excel, here are Laravel5 use Excel
1, adding excel library
Seen official documentation http://laravelacademy.org/post/2024.htmlChinese composer to use the mirror:
https://packagist.phpcomposer.com
There are two ways to enable this mirror service:
- System Global Configuration: about to add information to the Composer configuration global configuration file
config.json
in. See "method" - Single project configuration: add configuration information to a project
composer.json
file. See "Method II"
Method One: Modify composer global configuration file (the recommended way)
Open a command line window (windows users) or console (Linux, Mac users) and execute the following command:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
Method two: modify the current project composer.json
configuration file:
Open a command line window (windows users) or console (Linux, Mac user), into the root directory of your project (ie composer.json
file directory), execute the following command:
composer config repo.packagist composer https://packagist.phpcomposer.com
The above command will be in the current project of the composer.json
end of the file is automatically added mirrored configuration information (you can also manually add your own):
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
Laravel project to composer.json
the configuration file, for example, after executing the command shown in the above-described (note that the last few lines) as follows:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*"
},
"config": {
"preferred-install": "dist"
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
}
2, excel use
The official document: www.maatwebsite.nl/laravel-excel/docs/export
Official API there are some places insufficiency
Such as setting wrap
我们 打开 vendor \ custom website \ excel \ src \ Size Site \ Excel \ Classes \ LaravelExcelWorksheet.php
加入方法:
public function setWrapText($styles) { return $this->getStyle($styles)->getAlignment()->setWrapText(true);; } 使用如下:
$sheet->setWrapText('A1:K1',true);设置列宽
打开vendor\maatwebsite\excel\src\Maatwebsite\Excel\Writers\LaravelExcelWriter.php
加入方法
public function setWeight($styles,$weight){ return $this->excel->getActiveSheet()->getColumnDimension($styles)->setWidth($weight); }使用如下:
$excel->setWeight('B',17);以上是举例说明自己添加一些方法,具体可以查找一些PHPexcel的方法实现然后实现到自己的代码中,其实Excel类就是对PHPexcel的一个封装