From c04530a1be481148d38a6e6b3432c89033ca2382 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Mon, 25 May 2020 19:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/library/excel/Excel.php | 25 ++++++++++++++++----- extend/catcher/library/excel/MacroExcel.php | 13 +++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/extend/catcher/library/excel/Excel.php b/extend/catcher/library/excel/Excel.php index a01c0c1..67df9ea 100644 --- a/extend/catcher/library/excel/Excel.php +++ b/extend/catcher/library/excel/Excel.php @@ -3,7 +3,6 @@ namespace catcher\library\excel; use catcher\CatchUpload; use PhpOffice\PhpSpreadsheet\Exception; -use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use think\file\UploadedFile; @@ -36,9 +35,28 @@ class 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 $this->registerWorksheet(); + // before save excel + $this->before(); + // set excel title $this->setTitle(); @@ -50,13 +68,8 @@ class Excel // set worksheets $this->setWorksheets(); - - (new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($this->spreadsheet))->save($path); - - // $this->upload($disk, $path); } - /** * 设置 sheets * diff --git a/extend/catcher/library/excel/MacroExcel.php b/extend/catcher/library/excel/MacroExcel.php index 3f8e16b..57bfc66 100644 --- a/extend/catcher/library/excel/MacroExcel.php +++ b/extend/catcher/library/excel/MacroExcel.php @@ -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' ...] *