lib/IgraalOSL/StatsTable/Dumper/Excel/ExcelDumper.php
public function dump(StatsTable $statsTable)
    {
        $excel = new Spreadsheet();

        $excel->getDefaultStyle()->applyFromArray($this->getDefaultStyleArray());

        $sheet = $excel->getActiveSheet();

        $row = 1;
        $data = $statsTable->getData();
        $width = count(reset($data));

        // HEADERS //
        if ($this->enableHeaders) {
            $headerStyle = new Style();
            $headerStyle->applyFromArray($this->getHeadersStyleArray());

            $col = 0;
            foreach ($statsTable->getHeaders() as $header) {
                $sheet->setCellValueByColumnAndRow($col, $row, $header);
                $col++;
            }
            $sheet->duplicateStyle($headerStyle, 'A1:'. Coordinate::stringFromColumnIndex($width-1).'1');
            $row++;
        }

        // DATA //
        foreach ($statsTable->getData() as $data) {
            $this->applyValues($sheet, $row, $data, $statsTable->getDataFormats());
            $row++;
        }

        // AGGREGATIONS //
        if ($this->enableAggregation) {
            $this->applyValues($sheet, $row, $statsTable->getAggregations(), $statsTable->getAggregationsFormats(), $this->getAggregationsStyleArray());
        }

        // FINAL FORMATTING //
        for ($col = 0; $col < $width; $col++) {
            $sheet
                ->getColumnDimension(Coordinate::stringFromColumnIndex($col))
                ->setAutoSize(true);
        }

        $xlsDumper = new Xlsx($excel);
        $pFilename = @tempnam(sys_get_temp_dir(), 'phpxltmp');
        $xlsDumper->save($pFilename);
        $contents = file_get_contents($pFilename);
        @unlink($pFilename);

        unset($excel);
        unset($xlsDumper);

        return $contents;
    }
public function dump(StatsTable $statsTable)
    {
        $excel = new Spreadsheet();

        $excel->getDefaultStyle()->applyFromArray($this->getDefaultStyleArray());

        $sheet = $excel->getActiveSheet();

        $row = 1;
        $data = $statsTable->getData();
        $width = count(reset($data));

        // HEADERS //
        if ($this->enableHeaders) {
            $headerStyle = new Style();
            $headerStyle->applyFromArray($this->getHeadersStyleArray());

            $col = 0;
            foreach ($statsTable->getHeaders() as $header) {
                $sheet->setCellValueByColumnAndRow($col, $row, $header);
                $col++;
            }
            $sheet->duplicateStyle($headerStyle, 'A1:'. Coordinate::stringFromColumnIndex($width-1).'1');
            $row++;
        }

        // DATA //
        foreach ($statsTable->getData() as $data) {
            $this->applyValues($sheet, $row, $data, $statsTable->getDataFormats());
            $row++;
        }

        // AGGREGATIONS //
        if ($this->enableAggregation) {
            $this->applyValues($sheet, $row, $statsTable->getAggregations(), $statsTable->getAggregationsFormats(), $this->getAggregationsStyleArray());
        }

        // FINAL FORMATTING //
        for ($col = 0; $col < $width; $col++) {
            $sheet
                ->getColumnDimension(Coordinate::stringFromColumnIndex($col))
                ->setAutoSize(true);
        }

        $xlsDumper = new Xlsx($excel);
        $pFilename = @tempnam(sys_get_temp_dir(), 'phpxltmp');
        $xlsDumper->save($pFilename);
        $contents = file_get_contents($pFilename);
        @unlink($pFilename);

        unset($excel);
        unset($xlsDumper);

        return $contents;
    }
public function dump ( StatsTable $ statsTable ) { $ excel = new Spreadsheet ( ) ; $ excel -> getDefaultStyle ( ) -> applyFromArray ( $ this -> getDefaultStyleArray ( ) ) ; $ sheet = $ excel -> getActiveSheet ( ) ; $ row = 1 ; $ data = $ statsTable -> getData ( ) ; $ width = count ( reset ( $ data ) ) ; // HEADERS // if ( $ this -> enableHeaders ) { $ headerStyle = new Style ( ) ; $ headerStyle -> applyFromArray ( $ this -> getHeadersStyleArray ( ) ) ; $ col = 0 ; foreach ( $ statsTable -> getHeaders ( ) as $ header ) { $ sheet -> setCellValueByColumnAndRow ( $ col , $ row , $ header ) ; $ col ++ ; } $ sheet -> duplicateStyle ( $ headerStyle , 'A1:' . Coordinate :: stringFromColumnIndex ( $ width - 1 ) . '1' ) ; $ row ++ ; } // DATA // foreach ( $ statsTable -> getData ( ) as $ data ) { $ this -> applyValues ( $ sheet , $ row , $ data , $ statsTable -> getDataFormats ( ) ) ; $ row ++ ; } // AGGREGATIONS // if ( $ this -> enableAggregation ) { $ this -> applyValues ( $ sheet , $ row , $ statsTable -> getAggregations ( ) , $ statsTable -> getAggregationsFormats ( ) , $ this -> getAggregationsStyleArray ( ) ) ; } // FINAL FORMATTING // for ( $ col = 0 ; $ col < $ width ; $ col ++ ) { $ sheet -> getColumnDimension ( Coordinate :: stringFromColumnIndex ( $ col ) ) -> setAutoSize ( true ) ; } $ xlsDumper = new Xlsx ( $ excel ) ; $ pFilename = @ tempnam ( sys_get_temp_dir ( ) , 'phpxltmp' ) ; $ xlsDumper -> save ( $ pFilename ) ; $ contents = file_get_contents ( $ pFilename ) ; @ unlink ( $ pFilename ) ; unset ( $ excel ) ; unset ( $ xlsDumper ) ; return $ contents ; }
Dumps the stats table
@param  StatsTable $statsTable
@return string
@throws \Exception
Dumps the stats table