<?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

最新文章

  1. tomcat 配置项目指定域名
  2. VBA学习之关于数据透视表的应用
  3. 从零开始学习Node.js例子四 多页面实现数学运算
  4. Shell下的正则表达式 (鸟哥私房菜)
  5. sql语句(mysql)
  6. unity脚本的基础语法
  7. hdoj 2097 Sky数
  8. hdu 4612 (双联通+树形DP)
  9. 介绍map.entry接口
  10. 纯手工打造dropdownlist控件
  11. IOS设计模式学习(18)模板方法
  12. 1.cocos2dx 3.2环境结构
  13. zookeeper的单实例和伪集群部署
  14. Flume初入门简单配置与使用
  15. linux 3.10 一次softlock排查
  16. AngularJS学习笔记(五)自定义指令(1)
  17. PostgreSQL入门教程
  18. 调用oracle 各种报错总结---待续
  19. centos mysql忘记密码找回(仅限mysql5.7)
  20. 通过代码去执行testNG用例

热门文章

  1. elo system
  2. Spring系列之初识Spring Spring概述
  3. [SpringBoot项目]笔记
  4. Git进阶:常用命令和问题案例整理
  5. Scala的递归函数应用
  6. vue-router-next 通过hash模式访问页面不生效,直接刷新页面一直停留在根路由界面的解决办法
  7. Java中toCharArray()方法
  8. 整合mybatis与spring
  9. centos 端口测试之nc使用
  10. java进阶(23)--List接口