From 2c7f4837d55459531b5ace271deb58a497171047 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 11 Dec 2022 21:41:54 +0800 Subject: [PATCH] no message --- .../Controllers/Api/ProjectController.php | 3 +- app/Module/BillExport.php | 30 ++++++++++++------- app/Module/BillMultipleExport.php | 24 +++++++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 app/Module/BillMultipleExport.php diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 545d10d2f..47b537776 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -1124,9 +1124,8 @@ class ProjectController extends AbstractController } /** - * @api {get} api/project/task/down 20. 导出任务(限管理员) + * @api {get} api/project/task/down 20. 下载导出的任务 * - * @apiDescription 导出指定范围任务(已完成、未完成、已归档),返回下载地址,需要token身份 * @apiVersion 1.0.0 * @apiGroup project * @apiName task__down diff --git a/app/Module/BillExport.php b/app/Module/BillExport.php index c0b21f4ca..f7ca0108b 100644 --- a/app/Module/BillExport.php +++ b/app/Module/BillExport.php @@ -14,11 +14,12 @@ use PhpOffice\PhpSpreadsheet\Writer\Exception; class BillExport implements WithHeadings, WithEvents, FromCollection, WithTitle, WithStrictNullComparison { - public $title; - public $headings = []; - public $data = []; - public $typeLists = []; - public $typeNumber = 0; + protected $title; + protected $headings = []; + protected $data = []; + protected $typeLists = []; + protected $typeNumber = 0; + protected $styles = []; public function __construct($title, array $data) { @@ -57,15 +58,19 @@ class BillExport implements WithHeadings, WithEvents, FromCollection, WithTitle, return $this; } + public function setStyles(array $styles) + { + $this->styles = $styles; + return $this; + } + public function store($fileName = '') { if (empty($fileName)) { $fileName = date("YmdHis") . '.xls'; } try { return Excel::store($this, $fileName); - } catch (Exception $e) { - return "导出错误:" . $e->getMessage(); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (Exception|\PhpOffice\PhpSpreadsheet\Exception $e) { return "导出错误:" . $e->getMessage(); } } @@ -76,9 +81,7 @@ class BillExport implements WithHeadings, WithEvents, FromCollection, WithTitle, } try { return Excel::download($this, $fileName); - } catch (Exception $e) { - return "导出错误:" . $e->getMessage(); - } catch (\PhpOffice\PhpSpreadsheet\Exception $e) { + } catch (Exception|\PhpOffice\PhpSpreadsheet\Exception $e) { return "导出错误:" . $e->getMessage(); } } @@ -118,6 +121,11 @@ class BillExport implements WithHeadings, WithEvents, FromCollection, WithTitle, { return [ AfterSheet::Class => function (AfterSheet $event) { + if ($this->styles) { + foreach ($this->styles as $cell => $style) { + $event->sheet->getDelegate()->getStyle($cell)->applyFromArray($style); + } + } $count = count($this->data); foreach ($this->typeLists AS $cell => $typeList) { if ($cell && $typeList) { diff --git a/app/Module/BillMultipleExport.php b/app/Module/BillMultipleExport.php new file mode 100644 index 000000000..d03c461f1 --- /dev/null +++ b/app/Module/BillMultipleExport.php @@ -0,0 +1,24 @@ +data = $data; + } + + public function sheets(): array + { + return $this->data; + } +}