'project', 'B' => 'klant', 'C' => 'Nog te factureren incl. btw', 'D' => 'Nog te factureren incl. btw lopend boekjaar incl. btw', 'E' => 'Nog te factureren na lopend boekjaar inc. btw', 'F' => 'Nog te prognotiseren inc. btw' ]; private $invoiceForecast; private $sheet; private $row; public function __construct( $invoiceForecast, $sheet ) { $this->invoiceForecast = $invoiceForecast; $this->sheet = $sheet; $this->handle(); } private function handle() { $this->setHeader(); $this->setBody(); $this->setTotals(); } private function setHeader() { foreach ( self::HEADERS as $cell => $header ) { $this->sheet->setCellValue( $cell . '1', $header ); $this->sheet->getColumnDimension( $cell )->setAutoSize( TRUE ); } } private function setBody() { $this->row = 2; foreach ( $this->invoiceForecast AS $project ) { $this->sheet->setCellValue( 'A' . $this->row, $project['projectname'] ); $this->sheet->setCellValue( 'B' . $this->row, $project['customer'] ); $this->sheet->setCellValue( 'C' . $this->row, str_replace( '.', '', $project['needInvoice'] ) ); $this->sheet->setCellValue( 'D' . $this->row, str_replace( '.', '', $project['forecastThisYear'] ) ); $this->sheet->setCellValue( 'E' . $this->row, str_replace( '.', '', $project['forecastOtherYears'] ) ); $this->sheet->setCellValue( 'F' . $this->row, str_replace( '.', '', $project['forecastRemaining'] ) ); $this->row ++; } } private function setTotals() { $lastRow = $this->row - 1; $this->sheet->setCellValue( 'C' . $this->row, '=SUM(C2:C' . $lastRow . ')' ); $this->sheet->setCellValue( 'D' . $this->row, '=SUM(D2:D' . $lastRow . ')' ); $this->sheet->setCellValue( 'E' . $this->row, '=SUM(E2:E' . $lastRow . ')' ); $this->sheet->setCellValue( 'F' . $this->row, '=SUM(F2:F' . $lastRow . ')' ); } }