【发布时间】:2020-03-07 23:53:22
【问题描述】:
我需要使用 laravel 向 maatwesite excel 表格中的单元格添加公式,请帮我解决这个问题,如果可能的话可以添加,请建议代码
【问题讨论】:
-
您好,到目前为止您尝试了什么?请分享您的代码
-
@satish 你可以试试
WithMapping方法在单元格中添加公式吗?
我需要使用 laravel 向 maatwesite excel 表格中的单元格添加公式,请帮我解决这个问题,如果可能的话可以添加,请建议代码
【问题讨论】:
WithMapping 方法在单元格中添加公式吗?
添加公式其中一种方法是使用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,
];
}
}
【讨论】: