Laravel Maatwebsite Excel Data Import: サンプル データを含む Excel シートがあります。Excelデータをデータベースにアップロードする必要があります。Excelシートには、「正午」「Matnie」「Evening」「Night」という名前の列があり、その下に「AUD」と「GROSS」の2つのサブ列があります。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();
}
}
エクセルシート入力へのリンクはこちら エクセルシートのサンプルデータを入力
サンプル出力
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
]
}
]
エクセルシート入力へのリンクはこちら エクセルシートのサンプルデータを入力