我遇到了同样的问题。使用 Laravel 4。以下是我的控制器代码:
输出没有在管道分隔符上进行拆分,而是被视为一个长字符串。这里是一个示例:
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()
方法无法正常工作?