Wrap things up and send xlsx to browser.

@param string $fileName
357218
public function writeToBrowser($fileName = 'report.xlsx')
    {
        $this->output = fopen('php://output', 'w');
        $finalizer = new Finalizer($this->sheet, $this->styler, $this->sheetFile);
        $this->sendHeaders($fileName);
        $finalizer->finalize($this->output);
    }
165260
public function afterRender($filename) {
		$msgs = CakeSession::read('Alerts');
		
		if(empty($msgs)){
			return;
		}
		$out = array();
		$out[]= '<script type="text/javascript">';
		foreach($msgs as $msg){

			$out[] = sprintf('Rita.Alert.%s("%s");',$msg['type'],$msg['msg']);
		}
		$out[]= '</script>';
		$out = implode(' ',$out);
		
		$this->getView()->append('content',$out);
		CakeSession::write('Alerts',array());
	}
780005
public function save($fileName = null)
	{
		file_put_contents(empty($fileName) ? $this->fileName : $fileName, XML::toString($this->data), LOCK_EX);
	}
802524
public function export_to_file($filename)
    {
        $fh = fopen($filename, 'wb');
        if (!$fh) {
            return false;
        }
        $res = $this->export_to_file_handle($fh);
        fclose($fh);

        return $res;
    }
1353527
public function excel($filename, $data)
    {
        \Excel::create($filename, function ($excel) use ($filename, $data) {
            $excel->sheet($filename, function ($sheet) use ($data) {
                $sheet->fromArray($data);
            });
        })
              ->export('xlsx');
    }
820174
public function attachFile($file, $fileName = null)
    {
        if (gettype($file) == 'resource') {
            $this->file = ['fileName' => $fileName, 'fileContent' => $file];
        } else {
            $this->file = ['fileName' => $fileName, 'fileContent' => fopen($file, 'r')];
        }
    }
945920
protected function compress($filename, $xml)
    {
        if (!$this->compressor) {
            $this->compressor = new ZipFly();
        }

        return $this->compressor->compress($filename, $xml);
    }
183316
public function sendToBrowserDownload($filename)
    {
        ReportRenderer::sendToBrowser(
            $filename,
            ReportRenderer::CSV_FORMAT,
            "text/" . ReportRenderer::CSV_FORMAT,
            $this->getRenderedReport()
        );
    }
1120491
public function open($fileName)
    {
        $this->tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
        $this->zip = new PclZip($fileName);

        return true;
    }
1109738
public function output(string $filename)
    {
        $basename  = pathinfo($filename, PATHINFO_BASENAME);
        $this->save($basename, true);
    }
59878
public static function parseFromFile($filename)
    {
        if (file_exists($filename) && is_readable($filename)) {
            return new self(file_get_contents($filename));
        } else {
            throw new \RuntimeException(sprintf("File %s is not readable, or doesn't exist.", $filename));
        }
    }
397494
public function createSpreadsheet($filename = null)
    {
        return (null === $filename) ? new Spreadsheet() : call_user_func(array($this->phpSpreadsheetIO, 'load'), $filename);
    }
276151
public function exportToFile(string $filename)
    {
        if (($p = strrpos($filename, DIRECTORY_SEPARATOR)) >= 0) {
            $path = substr($filename, 0, $p);
            $name = substr($filename, $p + 1);

            if (strlen($path) > 0 && !is_dir($path)) {
                mkdir($path, 0755, true);
            }
        }

        if (($handler = fopen($filename, 'w'))) {
            fwrite($handler, $this->code);
            fclose($handler);
        }
    }
291504
public function setFileName($filename)
    {
        $this->load();
        $this->filename = $filename;
        $this->io = new Real($filename);
    }
292133
public function loadFile( $fileName )
	{
		if( !file_exists( $fileName ) )
			throw new Exception( 'XML File "'.$fileName.'" is not existing.' );
		$this->document	= new DOMDocument();
		$this->document->load( $fileName );
		$this->xPath	= new DOMXpath( $this->document );
		return true;
	}
977051
protected function addheader($filename)
    {
        $tempFilename = str_replace($this->fileExtension, '', $filename);

        $headerFilename = $tempFilename . '_header' . $this->fileExtension;

        $exportName = $this->getName();

        $writer = WriterFactory::create(Type::XLSX);
        $writer->openToFile($headerFilename);

        $header = $this->getColumnHeaders();
        if (isset($this->data[$exportName]) &&
                isset($this->data[$exportName]['format']) &&
                in_array('formatVariable', (array) $this->data[$exportName]['format'])) {
            $writer->addRow($header);
        } else {
            $writer->addRow(array_keys($header));
        }

        $writer->close();
    }
177888
public function handleRename(string $fileName): void
	{
		if ($this->presenter->isAjax() && $this->editable) {
			$this->template->files = [$this->rename($fileName)];
			$this->redrawControl('itemsContainer');
		} else {
			exit;
		}
	}