ci =& get_instance(); $this->invoiceReport = $invoiceReport; $this->ci->load->helper( 'download' ); $this->handle(); } private function handle() { $this->setSpreadsheet(); $this->setInvoiceSheet(); $this->setFilename(); $this->setFullPathname(); $this->createFile(); $this->downloadSpreadsheet(); } private function setSpreadsheet() { $this->spreadsheet = new Spreadsheet(); } private function setInvoiceSheet() { $invoiceSheet = new Worksheet( $this->spreadsheet, 'Facturen' ); $this->invoiceSheet = $this->spreadsheet->addSheet( $invoiceSheet ); new InvoiceSheet( $this->invoiceReport['invoiceOverview'], $this->invoiceSheet ); } private function setFilename() { $this->filename = 'facturen' . date( 'YmdHis' ) . '.xlsx'; } private function setFullPathname() { $this->fullpathname = MYROOTPATH . 'documents/spreadsheets/' . $this->filename; } private function createFile() { $writer = new Xlsx( $this->spreadsheet ); $writer->save( $this->fullpathname ); } private function downloadSpreadsheet() { $data = file_get_contents( $this->fullpathname ); force_download( $this->filename, $data ); } }