Laravel Maatwebsite Excel数据导入:我有一张带有一些示例数据的Excel表格。我需要将excel数据上传到数据库。在excel表格中,我有一个名为" Noon" " Matnie" "晚间"和"夜晚"在那之下有两个子列" AUD"和#34; 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工作表的链接在INPUT SAMPLE DATA OF 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工作表的链接在INPUT SAMPLE DATA OF EXCEL SHEET