Laravel-excel: CSV์—์„œ ์ธ์šฉ๋ฌธ ์ œ๊ฑฐ

์— ๋งŒ๋“  2015๋…„ 05์›” 22์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: Maatwebsite/Laravel-Excel

์•ˆ๋…•ํ•˜์„ธ์š” ์—ฌ๋Ÿฌ๋ถ„, ๋‚ด๋ณด๋‚ธ CSV ํŒŒ์ผ์„ ๋ฐ›์•˜์ง€๋งŒ ๋ชจ๋“  ์…€ ๋ฐ์ดํ„ฐ์— ๋”ฐ์˜ดํ‘œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. CSV๋กœ ๋‚ด๋ณด๋‚ผ ๋•Œ ๋”ฐ์˜ดํ‘œ๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ? ์—ฌ๊ธฐ ์˜ˆ:
"20150521","62549","2492","","16.52","1.98","0","0","0","","922330816001","","","P ","","2492"
"20150521","71343","2493","","8.26","0.99","0","0","0","","922330816001","","","P ","","2493"
๋‚˜๋Š” ์ด๊ฒƒ์„ ์›ํ•œ๋‹ค..
20150521,62549,2492,,16.52,1.98,0,0,0,,922330816001,,,P,,2492
20150521,71343,2493,,8.26,0.99,0,0,0,,922330816001,,,P,,2493
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

๋‚ด ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

//generating .csv
$csv = Excel::create($conciliacion->nombre, function($excel){
            $excel->sheet('Lista', function($sheet) {
                $empresa = Empresa::find(1);
                $conciliacion = Session::get('conciliacion');
                Session::forget('conciliacion');
                $fecha_conciliacion = $conciliacion->fecha;

                $i = 1;
                $ordenes = Orden::whereBetween('fecha_emision', array($fecha_conciliacion.' 00:00', $fecha_conciliacion.' 23:59'))->get();
                var_dump($ordenes);
                foreach($ordenes as $o){
                    $sheet->row($i, array(
                        (int)date("Ymd", strtotime($o->fecha_emision)),
                        (int)date("His", strtotime($o->fecha_emision)),
                        (int)$o->numero_orden,
                        (int)$o->tipo_tarjeta,
                        (float)number_format(($o->subtotal_12+$o->subtotal_0), 2),
                        (float)number_format($o->iva, 2),
                        (float)'0.00',
                        (float)number_format($o->intereses/100, 2),
                        (float)number_format($o->total_intereses/100, 2),
                        (int)$o->numero_autorizacion,
                        (int)$empresa->ruc,
                        (int)$o->tipo_credito,
                        (int)$o->meses_credito,
                        'P',
                        '',
                        (int)$o->numero_orden,
                    ));
                    $i++;
                }
            });
        })->export('csv');

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๊ตฌ์„ฑ์—์„œ enclosure ์„ค์ •์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. https://github.com/Maatwebsite/Laravel-Excel/blob/master/src/config/excel.php#L129

๋ชจ๋“  3 ๋Œ“๊ธ€

๊ตฌ์„ฑ์—์„œ enclosure ์„ค์ •์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. https://github.com/Maatwebsite/Laravel-Excel/blob/master/src/config/excel.php#L129

ํ›Œ๋ฅญํ•ฉ๋‹ˆ๋‹ค. Laravel์—์„œ ๊ตฌ์„ฑ ํŒŒ์ผ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ../vendor/maatwebsite/excel/src/config/csv.php ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
๊ตฌ์„ฑ์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ๋ฌธ์„œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์–ด์จŒ๋“  ๋‹ค์‹œ ํ•œ ๋ฒˆ ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

Laravel 4๋ผ๋ฉด ๊ทธ๋ ‡์Šต๋‹ˆ๋‹ค. ๋‚ด๊ฐ€ ์ค€ ์˜ˆ๋Š” ๊ตฌ์„ฑ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ด ์žˆ๋Š” Laravel 5์— ๋Œ€ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰