【问题标题】:Laravel-Excel CSV delimiter not workingLaravel-Excel CSV 分隔符不起作用
【发布时间】:2015-03-29 01:14:47
【问题描述】:

我也有同样的问题。使用 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() 方法不起作用?

【问题讨论】:

    标签: php laravel-4 phpexcel laravel-excel


    【解决方案1】:

    试试这个。

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

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

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      相关资源
      最近更新 更多