上面的图像是一个显示dd方法在laravel导入我的excel文件.问题是在processing它之后,其他列得到存储,但行23和25得到存储为0,但如果查看与microsoft excel软件它显示确切的数字,它假设.
<?php
namespace App\Imports;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use DB;
class SummaryImport implements ToCollection
{
/**
* @param Collection $collection
*/
public function collection(Collection $rows){
unset($rows[0]);
unset($rows[1]);
unset($rows[2]);
unset($rows[3]);
unset($rows[4]);
unset($rows[5]);
unset($rows[6]);
foreach ($rows as $key) {
// dd($key);
if($key[1] !== null){
DB::table('summary_uploads')->insert(
[
'lga' => $key[2],
'reg_voters' => $key[3],
'accred_voters' => $key[4],
'A' => $key[5],
'AA' => $key[6],
'AAC' => $key[7],
'ADC' => $key[8],
'ADP' => $key[9],
'APC' => $key[10],
'APGA' => $key[11],
'APM' => $key[12],
'APP' => $key[13],
'BP' => $key[14],
'LP' => $key[15],
'NNPP' => $key[16],
'NRM' => $key[17],
'PDP' => $key[18],
'PRP' => $key[19],
'SDP' => $key[20],
'YPP' => $key[21],
'ZLP' => $key[22],
'total_valid_votes' => $key[23],
'rejected_votes' => $key[24],
'total_votes_cast' => $key[25],
]
);
}
}
}
}
有效投票总数和投票总数始终存储为0
1条答案
按热度按时间yuvru6vn1#
通过实现WithCalculatedFormulas,它解决了这个问题。
**$key[23]和$key[25]**不再存储为0,而是存储为计算值。
感谢**Tobias k.**的评论,我只提供了一个更具解释性的示例