laravel - 我可以在 laravel 的 maatwebsite excel 中添加公式吗
问题描述
我需要使用 laravel 向 maatwesite excel 表格中的单元格添加公式请帮我解决这个问题是否可以添加如果可能请建议代码
解决方案
添加公式的方法之一是使用WithMapping
:
例如,您需要在单元格中添加值,如A2+1
use App\Customer;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithMapping;
class CustomersExportFormulas implements FromCollection, WithMapping
{
public function collection()
{
return Customer::all();
}
public function map($customer): array
{
return [
$customer->id,
'=A2+1',
$customer->first_name,
$customer->last_name,
$customer->email,
];
}
}
推荐阅读
- reactjs - 打字稿声明合并以扩展或覆盖模块类型或接口属性
- python - 使用 Dataset API 和 Keras 编写 summary.scalar
- android - 如何将数据从混合应用程序传递到本机应用程序?
- laravel - 如何为自定义面包生成器显示 Laravel voyager 侧边栏(添加帖子)
- c++ - 仅生成零的犰狳随机数生成器(Windows、MSYS2)
- pagespeed - PageSpeed Insights:同一站点的页面/测试运行之间的结果不一致(推迟屏幕外图像)
- r - 计算配对列并聚合
- html - 自动将文件从网站上传到社交平台
- python - 使用 bash 文件运行两个 python 脚本
- android - Gson 将 JSON 保存到磁盘并加载回内存