rap2hpoutre / fast-excel

🦉 Fast Excel import/export for Laravel
MIT License
2.09k stars 246 forks source link

CellAlignment right based column data #270

Closed safwanAzman closed 1 year ago

safwanAzman commented 2 years ago

im trying to cellAlignment right for number_format data only Salary,Total Share,Total Contribution and Monthly Contribution not all data at once, how i to make it? this is my code : public function generateExcel() { return response()->streamDownload(function () { $header_style = (new StyleBuilder()) ->setFontBold() ->setShouldWrapText(false) ->build(); $rows_style = (new StyleBuilder()) ->setShouldWrapText(false) ->build(); $right_style = (new StyleBuilder()) ->setCellAlignment(CellAlignment::RIGHT) ->build();
return (new FastExcel($this->renderReportList())) ->headerStyle($header_style) ->rowsStyle($rows_style) ->export('php://output' , function ($item) { $row = [ 'Membership No' => $item->ref_no, 'Name' => $item->name, 'Identity No' => $item->identity_no, 'Staff No' => $item->staff_no, 'Company Phone No' => $item->company_phone_no, 'Employment Date' => date('d-m-Y', strtotime($item->current_employment_date)), 'Salary' => number_format($item->current_salary,2), 'Approve Retirement Date' => date('d-m-Y', strtotime($item->approved_retirement_date)), 'Effective Retirement Date' => date('d-m-Y', strtotime($item->effective_retirement_date)), 'Date Joined' => date('d-m-Y', strtotime($item->start_date)), 'Total Share' => number_format($item->total_share,2), 'Total Contribution' => number_format($item->total_contribution,2), 'Monthly Contribution' => number_format($item->monthly_contribution,2), 'Gender' => $item->gender_id, ];
return $row; }); }, sprintf('ListOfMember-%s.xlsx',$this->startDate));

}

hope anyone help me thank you.