๋๋์ด CSV (ํ ๋จธ๋ฆฌ๊ธ ์์)๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
001001,BENITEZ LI,2052,2059,2016-04-27 09:07:20
001002,CASA PARRO,13937,13945,2016-04-21 09:07:20
001004,NUEVO BANC,701,709,2016-04-23 22:07:20
์ด ์คํฌ๋ฆฝํธ ์ฌ์ฉ:
Excel::filter('chunk')->load(public_path().'/uploads/'.$filename)->chunk(250, function($results) {
foreach ($results as $row) {
$user = Lectura::create([
'partida' => $row->partida,
'nombre' => $row->nombre,
'lectura_ant' => $row->lectura_ant,
'lectura_act' => $row->lectura_act,
'fecha' => $row->fecha,
]);
}
});
์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ์ฌ DB๋ก ๊ฐ์ ธ์ค๊ธฐ๋ฅผ ์ํฉ๋๋ค. ๊ฐ ์ค์ ์ฌ๋ฐ๋ฅด๊ฒ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ null ๊ฐ์ ์ฝ์ ํ์ญ์์ค. ๋คํ ํ ์ผ:
CellCollection {#734 โผ
#title: null
#items: array:5 [โผ
"001001" => "001002"
"benitez_li" => "CASA PARRO"
2052 => 13937.0
2059 => 13945.0
"2016_04_27_090720" => "2016-04-21 09:07:20"
]
}
์๋ง๋ (์ด ์ด๋ฆ์ ์ด๋ป๊ฒ ์ ์ํ ์ ์์ต๋๊น?):
CellCollection {#734 โผ
#title: null
#items: array:5 [โผ
"partida" => "001002"
"nombre" => "CASA PARRO"
"lectura_ant"=> 13937.0
"lectura_act"=> 13945.0
"fecha" => "2016-04-21 09:07:20"
]
}
๋๋ ๋ ๋์(๋ฐฐ์ด๋ก ๋ณํ). ์ด๋ป๊ฒ ๊ฐ์ ์ป์ ์ ์์ต๋๊น? $ํ[1], $ํ[2]....
CellCollection {#734 โผ
#title: null
#items: array:5 [โผ
"0" => "001002"
"1" => "CASA PARRO"
"2"=> 13937.0
"3"=> 13945.0
"4" => "2016-04-21 09:07:20"
]
}
์ค์ ์์ ๋นํ์ฑํํ ์ ์์ต๋๋ค: https://github.com/Maatwebsite/Laravel-Excel/blob/2.1/src/config/excel.php#L374
์ฌ์ฉํ์ฌ ์๋ํ์ต๋๋ค.
$records = Excel::load(storage_path($filename), function($reader) { $reader->noHeading = true; }, 'ISO-8859-1')->get();
๋๋ ์ด๊ฒ์ผ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.
$rows = Excel::load(public_path().'/uploads/'.$filename, function($reader) {
$reader->toArray();
$reader->noHeading();
})->get();
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฌ์ฉํ์ฌ ์๋ํ์ต๋๋ค.
$records = Excel::load(storage_path($filename), function($reader) { $reader->noHeading = true; }, 'ISO-8859-1')->get();