Tag: laravel 5.1

从Excel文件中获取结果时出错

我正在尝试从Excel文件中检索结果以保存在数据库列中。 这是我正在尝试的: public function addRecords(Request $request){ $file = $request->get('file'); //echo $file; Excel::load($file, function($reader){ $results = $reader->get()->toArray(); echo $results; foreach($results as $key => $value){ $sim = new Sim(); $sim->msisdn = $value['msisdn']; $sim->imei = $value['imei']; $sim->issued_to = $value['issued_to']; $sim->associated_with_employee = $value['associated_with_employee']; $sim->save(); } }); } 我收到错误: 未定义的索引:msisdn | imei | issued_to | associated_with_employee。 我在这里做错了什么?

Excel下载 – Laravel 5.1

我正在使用名为发票,invoiceduedates,payments三个表的雄辩的查询。所有的数据我出口到excel通过使用laravel下面的查询。 $pay=Invoice::with('invoiceduedates','payments')->where('Eventcode','=',$eventcode)->get(); $payment='';$invoicepay=array(); foreach($pay as $payble){ $x=0;$due='';$payment='';$i=0; foreach($payble->invoiceduedates as $duedate){ $x++; $due .= $duedate->date.','.$duedate->amount; if($x <= count($payble->invoiceduedates)-1){ $due.=","; } } foreach($payble->payments as $paydate){ $i++; $payment .= $paydate->adjust_mode.','.$paydate->recieved_amount; if($i <= count($payble->payments)-1){ $payment.=","; } } $invoicepay[]= array_merge(explode(',',$due),explode(',',$payment)); unset($due);unset($payment);unset($i);unset($x); } $export = json_decode(json_encode((array) $invoicepay), true); Excel::create('Data', function($excel) use ($export) { $excel->sheet('Inovice Data', function($sheet) use ($export) { $sheet->fromArray($export); $sheet->cells('A1:AE1', […]

导入Excel文件时出错

当我尝试使用laravel 5.1 maatweb包导入excel文件时,我收到以下错误 连载: 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed function如下: public function import() { $file=Input::file("file"); // Excel::load($file, function($reader) Excel::load($file)->chunk(100, function($reader) { $results = $reader->get(); foreach($results as $row): Vlist::create([ 'vname' =>$row->vname, 'vservice' =>$row->vservice, 'vphone' =>$row->vphone, 'vmobile' =>$row->vmobile, 'vemail' =>$row->vemail, 'vcontactperson' =>$row->vcontactperson, 'vaddress' =>$row->vaddress, 'vegpcno' =>$row->vegpcno, 'vcapitallimit' =>$row->vcapitallimit, 'vgrade' =>$row->vgrade, 'vremarks' =>$row->vremarks, 'user_id' =>Auth::user()->id ]); endforeach; }); return […]

如何将HTML上的CSS应用于Excel导出

我试图导出HTML到Excel格式使用PHP头,但CSS样式不适用于元素(而导出到Excel文件),我也尝试实现Bootstrap类,但没有运气 注意 :在应用引导类时,我在我的html中包含了bootstrap.css 有什么办法可以应用CSS? 头部使用 header('Content-type: application/excel'); header("Content-Disposition: attachment; filename=\"$filename\""); 示例HTML元素 <table width="100%" border="1" class="table table-striped table-bordered"> <thead> <tr> <td colspan="9" style="font-weight: bold; font-size: 16px; text-align: center;"><h2>Push Notification </h2></td> </tr> <tr><td colspan="9"></td></tr> </thead> <tbody> <tr class="heading"> <th colspan="2" ></th> <th style="width:2% !important">S.no</th> <th style="width:10% !important">Date</th> <th style="width:10% !important">App</th> <th style="width:20%">Category</th> <th colspan="2" style="width:50%">Message</th> </tr> @if($push_notifications->count() […]

用另一个数组sortingmultidimensional array,并以相同的顺序完成丢失的键

我试图使用PHP / Laravel将导出表中的数据导出为ex​​cel,可以自定义导出表以显示特定列,导出列应与表列相同。 问题是 – 如果列不存在于一个特定的行中,列不显示为空,'xls'文件导出非常混乱…我的代码如下所示: public function excelExport(Request $request, $client_id=null) { $client_id = is_null($client_id) ? \Auth::client()->id : $client_id; if(is_null($this->client_users)){ $this->client_users = $this->clientsController->listClientUsers($client_id); } $columns = $this->account_settings->getColumnsDef($client_id); $query = Lead::select(array_keys($columns))->where('client_id',strval($client_id))->where('deleted',0); $query = $this->setQueryDates($request,$query,$client_id); $query = $this->leadsFiltersController->setExportQuery($request,$query); $arr = $query->get()->toArray(); Excel::create('leads' , function($excel) use ($arr,$columns){ $excel->sheet('Leads' , function($sheet) use ($arr,$columns){ $rows = []; $count = 0; […]

用框架Laravel编辑一个exesting文件Excel

我想编辑一个名为'myfile'的现有文件,我只想在添加一些数据之前将其导出…我有这个问题: Excel2007.php中的PHPExcel_Reader_Exception第82行:无法打开C:\ laravel \ compta \ files / Med进行阅读! 文件不存在。 这是我在控制器中的代码: public function export(){ Excel::load('files/Med',function($excel) { $excel->sheet('Sheetname', function($sheet) { // Sheet manipulation }); })->export('xls'); } 我怎样才能导出文件“医学”?

导入utf-8标题Maatwebsite Laravel

我在Laravel使用Maatwebsite,它是非常好的Excel工程选项,但我有一个问题..我有excel表单与阿拉伯语标题,所以当我导入它时,它转换为理解less英文字符,以适应数组键。那么我的问题的解决scheme是什么?

join两个模型来获取数据

我这样查询我的模型 $projects = Project::where('status', '!=', 'Completed')->get(); 这会让我回到这样的事情 #attributes: array:16 [▼ "id" => "7" "user_id" => "32" "contactEmail" => "sdfsdf@dsfsdf.com" "deploymentDate" => "2016-07-29" "status" => "Starting" "deleted_at" => null "created_at" => "2016-07-12 14:12:32" "updated_at" => "2016-07-15 09:47:34" ] 然后我通过这个模型来生成一个Excel文件 Excel::create('projects', function($excel) use($projects) { $excel->sheet('Sheet 1', function($sheet) use($projects) { $sheet->fromArray($projects); }); })->export('xls'); 一切工作正常,并生成Excel。 我遇到的一个问题是,Excel文件显示user_id是32.而不是显示user_id,我想显示userName是我的用户表的一部分。 我怎样才能join这两个表来获得名称,而不是id? 所有关系都正确设置。 谢谢