나는 invoice, invoiceduedates, payments.So라는 3 개의 테이블을 가진 능변적인 쿼리를 사용하고 있는데, 나는 export하는 모든 데이터를 laravel에서 아래의 쿼리를 사용하여 Excel로 엑셀한다.Excel 다운로드 - Laravel 5.1
| Due Date1 | Due Amount1 | Due Date2 | Due Amount2 | AdjustMode1 | Rcv Amount1 | AdjustMode2 | Rcv Amount2 |
|------------|-------------|-----------------------|-------------|-----------------------|-------------|-----------------------|-------------|
| 2016-03-25 | 2000 | 2016-02-29 | 2000 | Overseas Bank Charges | 2000 | Overseas Bank Charges | 2743 |
| 2016-03-31 | 3750 | Overseas Bank Charges | 3708 | Overseas Bank Charges | 2750 | | |
그러나 때문에 DATE2의 열 invoiceduedates의 테이블에 초 기한이없는 경우 뭐죠 여기에 일어나고하는 것은, 때문에 AMOUNT2가 조정 모드 1과 겹쳐지고있다 : 아래
$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', function($cells)
{
$cells->setBackground('#000000');
$cells->setFontColor('#fff');
});
$sheet->row(1, array(
'Due Date1','Due Amount1','Due Date2','Due Amount2','AdjustMode1','Rcv Amount1','AdjustMode2','Rcv Amount2'
));
});
})->download('xlsx');
내 엑셀 결과입니다 RCV 금액 1.
실제 엑셀
어떻게 원하는 나는 것을 제어 할 수 empty.How 그 열이 원하는 어떠한 제 기한이없는 경우| Due Date1 | Due Amount1 | Due Date2 | Due Amount2 | AdjustMode1 | Rcv Amount1 | AdjustMode2 | Rcv Amount2 |
|------------|-------------|------------|-------------|-----------------------|-------------|-----------------------|-------------|
| 2016-03-25 | 2000 | 2016-02-29 | 2000 | Overseas Bank Charges | 2000 | Overseas Bank Charges | 2743 |
| 2016-03-31 | 3750 | | | Overseas Bank Charges | 3708 | Overseas Bank Charges | 2750 |
아 아래 foreach 루프 또는 엑셀의 헤더 부분? 도와주세요 .
감사합니다.
'$ export'에 빈 열이 있습니까? – weigreen
@weigreen 아니 그것은 내가 두 테이블에 여러 행에 데이터를 저장하기 때문에 없어. – 06011991
''$ duedate'와'$ paydate '는 최대 2 줄입니까? – weigreen