PHPExcel import Excel to mysql in Laravel 5
I need to upload Excel values in database field.My Excel file has rows values using laravel 5.
How to install phpexcel library in laravel 5 show my another tutorial.
Now you can use PHPEXCEL library in your controllers or middleware or library.
use PHPExcel;
use PHPExcel_IOFactory;
Import excel file to mysql in laravel 5 show below example.
$dir = 'assets/files/';
$filename = 'demo.xlsx';
$objPHPExcel = PHPExcel_IOFactory::load($dir . $filename);
$sheet_data = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
foreach($sheet_data as $data)
{
$post = new DiamondMaster;
$post->C_Name = $supplier_name;
$post->Loat_NO = $data['A'];
$post->C_Shape = $shape;
$post->C_Weight = $data['D'];
$post->C_Color = $C_Color;
$post->C_Clarity = $C_Clarity;
$post->C_NetD = $data['G'];
$post->C_Rap = $data['H'];
$post->C_Discount = $supplierdiscount;
$post->C_Rap = $data['J'];
$post->C_Cut = $C_Cut;
$post->C_Polish = $C_Polish;
$post->C_Symmetry = $C_Symmetry;
$post->C_Fluorescence = $C_Fluorescence;
$post->C_TableP = $data['R'];
$post->C_DefthP = $data['Q'];
$post->Lab = $data['S'];
$post->BGM = ($data['U'] != "") ? $data['U'] : '';
$post->gridle = $data['Y'];
$post->Crn_Ht = $data['Z'];
$post->Crn_Ag = $data['AA'];
$post->Pav_Ag = $data['AC'];
$post->Pav_Dp = $data['AB'];
$post->Certi_NO = $data['AD'];
$post->key_symbols = $data['AE'];
$post->C_Length = $C_Length;
$post->C_Width = $C_Width;
$post->C_Depth = $C_Depth;
$post->image = ($images != "") ? $images : '';
$post->Location = '16';
$post->is_delete = '0';
$post->save();
}
Leave a Reply