phpspreadsheet - 使用 Laravel Excel 在 Laravel 中设置 excel 样式
问题描述
学习 Laravel,我现在面临 Excel 导出。
在 Intenet Laravel Excel (docs.laravel-excel.com) 中搜索似乎是更好的选择,但我发现很难设置表格的样式(颜色、字体、大小等)
我在我的 AppServiceProvider 中使用全局事件侦听器:
Sheet::listen(AfterSheet::class, function () {
Sheet::macro('color_tab', function (Sheet $sheet, string $color) {
$sheet->getDelegate()->getTabColor()->setRGB($color);
});
});
然后我在我的导出类中使用它:
...
public function __construct($color) {
$this->color = $color;
}
...
use RegistersEventListeners;
...
public static function afterSheet(AfterSheet $event) {
// this is an error because it's a static method!
$event->sheet->color_tab($this->color);
}
问题是我必须用构造函数中给定的颜色为选项卡着色,但我不能,因为所有这些用于设置 Excel 样式的方法都是静态的。
我怎样才能做到这一点?
是否有另一个好的库来导出 Excel?用一种更简单的方式来做造型。
谢谢!
解决方案
最后我决定直接使用 PhpSpreadSheet 库而不使用包装器 Laravel Excel
推荐阅读
- python - 在Python中从一个文件到另一个文件提取数据
- php - PHP - Array_combine first row missing
- javascript - how to validate whether a specific email exist in the firebase database and how to fetch it for log in validation
- kotlin - 将 Firebase 列表视图转换为 Firestore 列表视图
- python - 在 Python 中构建迭代器
- javascript - Cloud Functions Puppeteer TimeoutError:尝试连接到 Chrome 时在 30000 毫秒后超时
- square-connect - square-commerce-v1 带回窗口而不是新标签
- java - 当同时存在泛型和通配符时如何推断参数类型
- sql - 合并三个表并在 oracle 中显示它们的状态(仅共享字段的最近条目)
- c# - EWS 减少邮箱连接时间