选择查询后的输出数组如下:
Array
(
[0] => Array
(
[nonrem_id] => 1
[nonrem_bank_accno] => 001-4537145-46
[nonrem_bank_name] => Axis
[nonrem_uniq_num] => BEUP3832618
[nonrem_receipt_number] => 123456
[nonrem_gl_date] => 2017-02-01
[nonrem_remit_date] => 2017-02-01
[nonrem_customer_name] => ABC
[nonrem_payment_method] => WIRE
[nonrem_ustatus] => NEGOTIABLE
[nonrem_currency] => EUR
[nonrem_trans_amount] => 74.97
[nonrem_acct_amt] => 65.31999999999999
[nonrem_variance] => 5.0E-11
[nonrem_cstatus] => Closed
[nonrem_assigned] => ssc.BERcptcreation
[nonrem_autoclosed] => Yes
[nonrem_created_date] => 2017-04-28 09:50:39
[nonrem_lastupdate] => 2017-04-28 11:26:21
[nonrem_created_by_name] => ILANGOVAN Thilagam
[comments] =>
)
[1] => Array
(
[nonrem_id] => 2
[nonrem_bank_accno] => 001-4537145-46
[nonrem_bank_name] => BNP PARIBAS FORTIS
[nonrem_uniq_num] => BEUP3836443
[nonrem_receipt_number] => 67890
[nonrem_gl_date] => 2017-02-01
[nonrem_remit_date] => 2017-02-01
[nonrem_customer_name] => XYZ
[nonrem_payment_method] => WIRE
[nonrem_ustatus] => NEGOTIABLE
[nonrem_currency] => EUR
[nonrem_trans_amount] => 74.97
[nonrem_acct_amt] =>
[nonrem_variance] => 5.0E-11
[nonrem_cstatus] => Closed
[nonrem_assigned] => ssc.BERcptcreation
[nonrem_autoclosed] => Yes
[nonrem_created_date] => 2017-04-28 09:50:39
[nonrem_lastupdate] => 2017-04-28 11:26:21
[nonrem_created_by_name] => ILANGOVAN Thilagam
[comments] =>
)
[2] => Array
(
[nonrem_id] => 3
[nonrem_bank_accno] => 001-4537145-46
[nonrem_bank_name] => Axis
[nonrem_uniq_num] => BEUP3832700
[nonrem_receipt_number] => 123456
[nonrem_gl_date] => 2017-02-01
[nonrem_remit_date] => 2017-02-01
[nonrem_customer_name] => ABC
[nonrem_payment_method] => WIRE
[nonrem_ustatus] => NEGOTIABLE
[nonrem_currency] => EUR
[nonrem_trans_amount] => 74.97
[nonrem_acct_amt] => 65.31999999999999
[nonrem_variance] => 5.0E-11
[nonrem_cstatus] => Open
[nonrem_assigned] => ssc.beappayment@cma-cgm.com
[nonrem_autoclosed] => No
[nonrem_created_date] => 2017-05-04 11:19:01
[nonrem_lastupdate] => 2017-05-04 11:19:01
[nonrem_created_by_name] => ILANGOVAN Thilagam
[comments] =>
)
[3] => Array
(
[nonrem_id] => 4
[nonrem_bank_accno] => 001-4537145-46
[nonrem_bank_name] => BNP PARIBAS FORTIS
[nonrem_uniq_num] => BEUP3836701
[nonrem_receipt_number] => 67890
[nonrem_gl_date] => 2017-02-01
[nonrem_remit_date] => 2017-02-01
[nonrem_customer_name] => XYZ
[nonrem_payment_method] => WIRE
[nonrem_ustatus] => NEGOTIABLE
[nonrem_currency] => EUR
[nonrem_trans_amount] => 74.97
[nonrem_acct_amt] => 60
[nonrem_variance] => 5.0E-11
[nonrem_cstatus] => Open
[nonrem_assigned] => ssc.BERcptcreation
[nonrem_autoclosed] => No
[nonrem_created_date] => 2017-05-04 11:19:02
[nonrem_lastupdate] => 2017-05-04 11:19:02
[nonrem_created_by_name] => ILANGOVAN Thilagam
[comments] =>
)
)
我的标题数组如下:
Array
(
[0] => Ref id
[1] => Bank Account Number
[2] => Bank Name
[3] => Unique number
[4] => Receipt Number
[5] => GL Date
[6] => Remit Date
[7] => Customer Name
[8] => Payment Method
[9] => Uploaded Status
[10] => Currency
[11] => Transaction Amount
[12] => Accounted Amount
[13] => Variance
[14] => Status
[15] => Assigned
[16] => Auto Closed
[17] => Uploaded Date
[18] => LastUpdated Date
[19] => Uploaded By
[20] => Comments
)
我正在使用Maatwebsite for Excel下载.. 我确实得到了下载的文件,但问题是我希望标题来自headers数组而不是它接受Select查询结果数组的索引。
请帮帮我。
答案 0 :(得分:0)
在单独的数组中进行标题并将其值作为数组传递给插入标题行..
dialog.dismiss()
在迭代循环后插入其他行。
答案 1 :(得分:0)
试试这个原因..下面的例子是5列..
$row_count = 0;
$obj_time = Carbon\Carbon::now();
$current_time = $obj_time->toDateTimeString();
$filename = 'report_'.$current_time;
Excel::create($filename, function($excel) use($row_count, $data){
$excel->sheet('Data', function($sheet) use($row_count, $data){
$sheet->setOrientation('landscape');
$sheet->cells('A1', function($cells) {
$cells->setFontWeight('bold');
$cells->setFontSize(14);
});
$sheet->setHeight(3, 25);
$sheet->cells('A3:E3', function($cells) {
$cells->setBackground('#f2f2f2');
$cells->setFontColor('#000000');
$cells->setFontWeight('bold');
$cells->setFontSize(12);
$cells->setValignment('center');
});
$sheet->row(3, array(
'Ref id', 'Bank Account Number', 'Bank Name', 'Unique number', 'Receipt Number'
));
$row_count = 4;
for($i=0; $i<count($data); $i++)
{
$sheet->row($row_count, array(
$data[$i]->nonrem_id, $data[$i]->nonrem_bank_accno, $data[$i]->nonrem_bank_name,$data[$i]->nonrem_uniq_num, $data[$i]->nonrem_receipt_number
));
$row_count++;
}
$row = $row_count-1;
$sheet->setBorder('A3:E'.$row, 'thin');
$sheet->cells('L3:E'.$row, function($cells) {
$cells->setAlignment('center');
});
$row_count++;
});
})->export('xls');