【问题标题】:can i add formula in maatwebsite excel in laravel我可以在 laravel 的 maatwebsite excel 中添加公式吗
【发布时间】:2020-03-07 23:53:22
【问题描述】:

我需要使用 laravel 向 maatwesite excel 表格中的单元格添加公式,请帮我解决这个问题,如果可能的话可以添加,请建议代码

【问题讨论】:

  • 您好,到目前为止您尝试了什么?请分享您的代码
  • @satish 你可以试试WithMapping 方法在单元格中添加公式吗?

标签: laravel maatwebsite-excel


【解决方案1】:

添加公式其中一种方法是使用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,
        ];
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2022-01-26
    • 2021-02-18
    相关资源
    最近更新 更多