我遇到了同样的问题。使用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()
方法不起作用?
答案 0 :(得分:6)
试试这个。
Config::set('excel.csv.delimiter', '|');
更多阅读 https://github.com/Maatwebsite/Laravel-Excel/issues/262