我有同样的问题。使用 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||
)
)
)
我在这里做错了吗?为什么不在管道字符上解析行?
如果我更改 中的delimiter
设置config/csv.php
,则文件被正确解析,结果如下所示:
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()
?