1

Laravel Maatwebsite Excel 数据导入:我有一个带有一些示例数据的 Excel 表。我需要将excel数据上传到数据库。在 Excel 表中,我有一个名为“Noon”“Matnie”“Evening”和“Night”的列,下面有两个子列“AUD”和“GROSS”。在使用 laravel 从 Excel 工作表中提取数据时,我只得到了“GROSS”字段的数据,而另一个字段丢失了。

控制器

<?php

namespace App\Http\Controllers;
use Input;

use DB;
use Excel;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class ExcelController extends Controller
{
  public function importExport()
    {
        return view('importExport');
    }

    public function importExcel()
    {
        if(Input::hasFile('import_file')){

            $path = Input::file('import_file')->getRealPath();
            $data = Excel::load($path, function($reader) {
            })->get();
        if(!empty($data) && $data->count()){

                foreach ($data as $key => $value) {
                    $theater_values[] = [$value];


            }
        dd($theater_values);
            }
        }
        return back();
    }
}

输入excel表的链接在这里输入EXCEL SHEET的样本数据

样本输出

array:11 [▼
  0 => array:1 [▼
    "theater_name" => CellCollection {#716 ▼
      #title: null
      #items: array:7 [▼
        "station" => null
        "theatre" => null
        "noon" => "AUD"
        0 => "GROSS"
        "matinee" => "AUD"
        "evening" => "AUD"
        "night" => "AUD"
      ]
    }
  ]
  1 => array:1 [▼
    "theater_name" => CellCollection {#702 ▼
      #title: null
      #items: array:7 [▼
        "station" => "Nellai"
        "theatre" => "Sri Rathna"
        "noon" => 249.0
        0 => 41000.0
        "matinee" => 386.0
        "evening" => 595.0
        "night" => 300.0
      ]
    }
  ]
  2 => array:1 [▼
    "theater_name" => CellCollection {#700 ▼
      #title: null
      #items: array:7 [▼
        "station" => "Tutucorin"
        "theatre" => "Raj cine complex"
        "noon" => 139.0
        0 => 21440.0
        "matinee" => 342.0
        "evening" => 597.0
        "night" => 202.0
      ]
    }
  ]

输入excel表的链接在这里输入EXCEL SHEET的样本数据

4

0 回答 0