删除表父阵列进口,以收集或列在Laravel Excel软件包

0

的问题

我想进的Excel但是,只有在片索引[0],但当我用toCollection或toArray方法的行包裹上片的指标阵列:

我想除去的包裹父阵列,如何做到这一点?

这里是我的代码:

Import.php

<?php

namespace App\Imports;

use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class Import implements SkipsEmptyRows,
                        WithCalculatedFormulas,
                        WithMultipleSheets
{
    use Importable;

    /**
     * Select sheet by index and how they are
     * mapped to specific import object.
     *
     * @return array
     */
    public function sheets(): array
    {
        return [
            0 => new static(),
        ];
    }
}

控制器:

$filePath = 'import-excel.xlsx';
$import = new Import();
$rows = $import->toCollection($filePath);

dd($rows->toArray());

预期成果:

[0] => Array(
    [0] => *Contact Name
    [1] => *Contact Email
    [2] => *Contact Address
)

[1] => Array (
    [0] => Talia Oktaviani S.Psi
    [1] => [email protected]
    [2] => Ds. Abdul No. 618 Tarakan 11408 KalU
)

实际的结果:

Array(  <== ***I want remove this.***
    [0] => Array(  <== ***I want remove this.***
        [0] => Array(
            [0] => *Contact Name
            [1] => *Contact Email
            [2] => *Contact Address
        )

        [1] => Array (
            [0] => Talia Oktaviani S.Psi
            [1] => [email protected]
            [2] => Ds. Abdul No. 618 Tarakan 11408 KalU
        )
    )  <== ***I want remove this.***
)  <== ***I want remove this.***
arrays excel import laravel
2021-11-24 00:35:38
1

最好的答案

1

你可以删除,如果采用功能的崩溃

$filePath = 'import-excel.xlsx';
$import = new Import();
$rows = $import->toCollection($filePath)->collapse();

dd($rows->toArray());
2021-11-25 14:29:13

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................