优化 excel

This commit is contained in:
JaguarJack 2020-05-25 19:55:25 +08:00
parent 2074c1f65d
commit c04530a1be
2 changed files with 32 additions and 6 deletions

View File

@ -3,7 +3,6 @@ namespace catcher\library\excel;
use catcher\CatchUpload; use catcher\CatchUpload;
use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use think\file\UploadedFile; use think\file\UploadedFile;
@ -36,9 +35,28 @@ class Excel
{ {
$this->excel = $excel; $this->excel = $excel;
$this->init();
(new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($this->spreadsheet))->save($path);
// $this->upload($disk, $path);
}
/**
* init excel
*
* @time 2020年05月25日
* @throws Exception
* @return void
*/
protected function init()
{
// register worksheet for current excel // register worksheet for current excel
$this->registerWorksheet(); $this->registerWorksheet();
// before save excel
$this->before();
// set excel title // set excel title
$this->setTitle(); $this->setTitle();
@ -50,13 +68,8 @@ class Excel
// set worksheets // set worksheets
$this->setWorksheets(); $this->setWorksheets();
(new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($this->spreadsheet))->save($path);
// $this->upload($disk, $path);
} }
/** /**
* 设置 sheets * 设置 sheets
* *

View File

@ -52,6 +52,19 @@ trait MacroExcel
} }
} }
/**
* before
*
* @time 2020年05月25日
* @return void
*/
protected function before()
{
if (method_exists($this->excel, 'before')) {
$this->excel->before();
}
}
/** /**
* 设置 column 信息 ['A', 'B', 'C' ...] * 设置 column 信息 ['A', 'B', 'C' ...]
* *