【问题标题】:How to get result of the formula on import xlsx with maatwebsite using Laravel? I get formula and not value of the formula如何使用 Laravel 通过 maatwebsite 获取导入 xlsx 公式的结果?我得到公式而不是公式的值
【发布时间】:2022-05-05 15:00:13
【问题描述】:

请指教! 在导入 xlsx 文件期间,我得到公式而不是公式的结果。

将配置文件 excel.php 更改为设置 'calculate'=> true,在导入时仍然不起作用。

我的模特

namespace App\Imports;

use App\ImpData;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;

class ImpDataImport implements ToModel
{
    public function model(array $row)
    {
        return new ImpData([
            'f1' => $row[1],
            'f2' => $row[2],
            'f3' => $row[3],
            'f4' => $row[4],
            'f5' => $row[5],
            'f6' => $row[6],
            'f7' => $row[7],
            'f8' => $row[8],
            'f9' => $row[9],
            'f10' => $row[10],
            'f11' => $row[11],
            'f12' => $row[12],
            'f13' => $row[13],
            'f14' => $row[14],
            'f15' => $row[15],
            'f16' => $row[16],
            'f17' => $row[17],
            'f18' => $row[18]
        ]);
    }
}

在我的控制器中

$data = Excel::toArray(new ImpDataImport(), $file);

源文件:

A1 = '1'
A2 = '2'
A3 = '=A1+B1'

导入后我得到:

array:1 [▼
  0 => array:1 [▼
    0 => array:3 [▼
      0 => 1.0
      1 => 2.0
      2 => "=A1+B1"
    ]
  ]
]

【问题讨论】:

  • 嘿,你解决过这个问题吗?

标签: php laravel maatwebsite-excel


【解决方案1】:

你需要将你的类定义为

class ImpDataImport implements ToModel, WithCalculatedFormulas

让它工作。刚刚为这个问题的任何未来观众添加了这个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多