gpt4 book ai didi

php - Laravel-Excel CSV 分隔符不起作用

转载 作者:可可西里 更新时间:2023-11-01 00:31:21 24 4
gpt4 key购买 nike

我遇到了同样的问题。使用 Laravel 4。这是来 self 的 Controller 的代码:

public function uploadData()
{
$file = Input::file('data')->getRealPath();

\Excel::load($file, function($reader) {
echo "<pre>";
$reader->setDelimiter('|');
print_r($reader->get());
});
}

输出未在管道分隔符上拆分,而是被视为一个长字符串。这是一个示例:

Maatwebsite\Excel\Collections\RowCollection Object
(
[title:protected] => Worksheet
[items:protected] => Array
(
[0] => Maatwebsite\Excel\Collections\CellCollection Object
(
[title:protected] =>
[items:protected] => Array
(
[upc_numberitem_numberqty_availunit_pricedescriptioncolorqty_on_ponext_avail_dt] => 040176424354|53607-3037|0|14.50|PACK-N-GO DUFFELS 20?"|BIRDS ON A WIRE/LEAF GREEN||
)

)

[1] => Maatwebsite\Excel\Collections\CellCollection Object
(
[title:protected] =>
[items:protected] => Array
(
[upc_numberitem_numberqty_availunit_pricedescriptioncolorqty_on_ponext_avail_dt] => 040176414850|53607-3054|0|14.50|PACK-N-GO DUFFELS 20?"|BLACK/BLACK/BLACK||
)

)
)

我是不是做错了什么?为什么不在管道字符上解析行?

如果我更改 config/csv.php 中的 delimiter 设置,文件将被正确解析,结果如下所示:

Maatwebsite\Excel\Collections\RowCollection Object
(
[title:protected] => Worksheet
[items:protected] => Array
(
[0] => Maatwebsite\Excel\Collections\CellCollection Object
(
[title:protected] =>
[items:protected] => Array
(
[upc_number] => 40176424354
[item_number] => 53607-3037
[qty_avail] => 0
[unit_price] => 14.5
[description] => PACK-N-GO DUFFELS 20?"
[color] => BIRDS ON A WIRE/LEAF GREEN
[qty_on_po] =>
[next_avail_dt] =>
)

)

[1] => Maatwebsite\Excel\Collections\CellCollection Object
(
[title:protected] =>
[items:protected] => Array
(
[upc_number] => 40176414850
[item_number] => 53607-3054
[qty_avail] => 0
[unit_price] => 14.5
[description] => PACK-N-GO DUFFELS 20?"
[color] => BLACK/BLACK/BLACK
[qty_on_po] =>
[next_avail_dt] =>
)

)

为什么它不能使用 setDelimiter() 方法?

最佳答案

试试这个。

Config::set('excel.csv.delimiter', '|');

阅读更多 https://github.com/Maatwebsite/Laravel-Excel/issues/262

关于php - Laravel-Excel CSV 分隔符不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29324567/

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