laravel设置excel高度
2024-10-09 20:25:00
<?php use App\Services\UploadService;
use Maatwebsite\Excel\Facades\Excel; class ExcelTest extends \TestCase
{
/**
* phpunit --filter testAdd tests/admin/AlbumTest.php
* author: costalong
* email: longqiuhong@163.com
*/
public function testRead()
{
$file = 'https://bucket-crm-1258058953.cos.ap-guangzhou.myqcloud.com/5b3be774c0eede35e264f6d740e5d8c8.xls';
$arr = explode('/',$file);
$file_name = "/tmp/".end($arr);
file_put_contents($file_name,file_get_contents($file)); Excel::load($file_name, function($reader) {
$sheetCounts = $reader->getSheetCount();
if($sheetCounts > 1){
throw new \Exception("只能1个sheet");
}
$reader = $reader->getSheet(0);
$res = $reader->toArray();
var_dump($res);
$header = $res[0];
if($header[0] != '导入地区' || $header[1] != '姓名' || $header[2] != '微信' || $header[3] != '手机号码'){
throw new \Exception("格式不规范");
}
}); unlink($file_name);
} /**
* author: costalong
* email: longqiuhong@163.com
*/
public function testWrite()
{
$cellData = [
['学号','姓名','成绩'],
['1000133333333333333333333333333333','AAAAA','99'],
['100023333333333333333333333','BBBBB','92'],
['10003','CCCCC','95'],
['10004','DDDDD','89'],
['10005','EEEEE','96'],
];
// Excel::create('学生成绩',function($excel) use ($cellData){
// $excel->sheet('score', function($sheet) use ($cellData){
// $sheet->rows($cellData);
// });
// })->export('xls'); $file_name = 'test';
$res = Excel::create($file_name,function($excel) use ($cellData){
$excel->sheet('score', function($sheet) use ($cellData){
$sheet->rows($cellData);
$sheet->setFontSize(15); // Alignment
$style = array(
'alignment' => array(
'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
)
);
$sheet->getDefaultStyle()->applyFromArray($style); $sheet->setWidth(array(
'A' => 50,
'B' => 30,
'C' => 15,
'D' => 10
));
$sheet->setHeight(array(
1 => 20,
2 => 20,
3 => 20,
4 => 20,
5 => 20
)); });
});
$res->store('xls'); // $file = base_path()."/storage/exports/".$file_name.".xls";
// $res =(new UploadService())->uploadFile($file,'businessCard/xls/export/'.$file_name.'.xls');
// dd($res);
// unlink($file);
}
}
https://www.jianshu.com/p/bcacb942ce8e
https://blog.csdn.net/sunjinyan_1/article/details/80927748
最新文章
- tomcat 配置项目指定域名
- VBA学习之关于数据透视表的应用
- 从零开始学习Node.js例子四 多页面实现数学运算
- Shell下的正则表达式 (鸟哥私房菜)
- sql语句(mysql)
- unity脚本的基础语法
- hdoj 2097 Sky数
- hdu 4612 (双联通+树形DP)
- 介绍map.entry接口
- 纯手工打造dropdownlist控件
- IOS设计模式学习(18)模板方法
- 1.cocos2dx 3.2环境结构
- zookeeper的单实例和伪集群部署
- Flume初入门简单配置与使用
- linux 3.10 一次softlock排查
- AngularJS学习笔记(五)自定义指令(1)
- PostgreSQL入门教程
- 调用oracle 各种报错总结---待续
- centos mysql忘记密码找回(仅限mysql5.7)
- 通过代码去执行testNG用例