gpt4 book ai didi

excel - laravel excel 获取标题和 maatwebsite

转载 作者:行者123 更新时间:2023-12-02 07:01:26 26 4
gpt4 key购买 nike

我只想获取 Excel 第一列,该列将作为列名称。

我正在使用此代码

Excel::load($request->file, function ($reader) use($request) {

$torarray=$reader->toArray();
$line0 = $torarray[0];
$headers = array_keys($line0);
$excel_header=$headers;
});

有时有效,有时无效。当不处理某些文件时,我在下面写并且可以工作

$torarray=$reader->toArray();
$line0 = $torarray[0][0];
$headers = array_keys($line0);
$excel_header=$headers;
});

我不明白什么是正确的解决方案。

最佳答案

谢谢@mahmoud-zalt

只是想分享我如何在 Laravel 5.5 中使用它:

$reader = Excel::load(storage_path() . '/uploads/tracking-number/' . $fileName)->get();
$headerRow = $reader->first()->keys()->toArray();

JSON:

["date","reference_no","tracking_notrace_webhttpwww.17track.com_for_eub_and_httpwww.cacesapostal.com_for_swiss_post","destination_country","receiver","tel","state","city","post_code","address","weightkg","quantity","valueusd","description","parcelquantity",0]

var_export:

array (
0 => 'date',
1 => 'reference_no',
2 => 'tracking_notrace_webhttpwww.17track.com_for_eub_and_httpwww.cacesapostal.com_for_swiss_post',
3 => 'destination_country',
4 => 'receiver',
5 => 'tel',
6 => 'state',
7 => 'city',
8 => 'post_code',
9 => 'address',
10 => 'weightkg',
11 => 'quantity',
12 => 'valueusd',
13 => 'description',
14 => 'parcelquantity',
15 => 0,
)

print_r

Array
(
[0] => date
[1] => reference_no
[2] => tracking_notrace_webhttpwww.17track.com_for_eub_and_httpwww.cacesapostal.com_for_swiss_post
[3] => destination_country
[4] => receiver
[5] => tel
[6] => state
[7] => city
[8] => post_code
[9] => address
[10] => weightkg
[11] => quantity
[12] => valueusd
[13] => description
[14] => parcelquantity
[15] => 0
)

关于excel - laravel excel 获取标题和 maatwebsite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40799404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com