3

I'm having the same problem. Using Laravel 4. Here's the code from my controller:

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

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

The output is not being split on the pipe separator, instead it's being treated as one long string. Here's a sample:

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||
                        )

                )
)

Am I doing something wrong here? Why aren't the rows being parsed on the pipe character?

If I change the delimiter setting in config/csv.php, the file is parsed correctly, and the result looks like this:

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] => 
                        )

                )

Why doesn't it work using the setDelimiter() method?

flyingL123
  • 7,686
  • 11
  • 66
  • 135

1 Answers1

6

try this.

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

for more read https://github.com/Maatwebsite/Laravel-Excel/issues/262

Roshan Perera
  • 780
  • 7
  • 12