@param Spreadsheet $spreadsheet
@param array $totals

@throws \Exception
188959
protected static function setFooterTotals( &$spreadsheet, $totals ) {
        // Create a map array by iterating through the headers
        $aHeaderMap = [];
        $lastColumn = $spreadsheet->setActiveSheetIndex( 0 )
                                  ->getHighestColumn();
        $lastColumn++; //Because of the != iterator below, we need to tell it to stop one AFTER the last column. Or we could change it to a doWhile loop... This was easier.

        $startColumn = 'A';

        for ( $c = $startColumn; $c != $lastColumn; $c++ ):
            $cellValue        = $spreadsheet->setActiveSheetIndex( 0 )
                                            ->getCell( $c . 1 )
                                            ->getValue();
            $aHeaderMap[ $c ] = $cellValue;
        endfor;


        $lastRow        = $spreadsheet->setActiveSheetIndex( 0 )
                                      ->getHighestRow();
        $footerRowStart = $lastRow + 1;

        foreach ( $totals as $field => $value ):
            // GET THE FIELD LETTER
            // Find the matching value in row one...
            $columnLetter = array_search( $field, $aHeaderMap );

            if ( $columnLetter === FALSE ):
                throw new \Exception( "EXCEPTION: " . $field . " was not found in " . print_r( $aHeaderMap, TRUE ) );
            endif;


            // If the value is not scalar, then
            if ( is_array( $value ) ):
                $multiDimensionalFooterRow = $footerRowStart;
                foreach ( $value as $name => $childValue ):
                    $spreadsheet->setActiveSheetIndex( 0 )
                                ->setCellValueExplicit( $columnLetter . $multiDimensionalFooterRow, $childValue, DataType::TYPE_STRING );
                    $multiDimensionalFooterRow++;
                endforeach;
            else:
                $spreadsheet->setActiveSheetIndex( 0 )
                            ->setCellValueExplicit( $columnLetter . $footerRowStart, $value, DataType::TYPE_STRING );
            endif;

        endforeach;
    }
46617
protected function assertSay($what, $totalTimes, $arguments = array())
    {
        $semiHash = serialize(array($what, $arguments));
        $this->expectedSay[$semiHash] = $totalTimes;
        return $this;
    }
612636
private function splitRanges(string $ranges): void
    {
        $matches = [];
        if (!preg_match('#^[\-|\+]{1}([0-9]+),([0-9]+) [\-\+]{1}([0-9]+),([0-9]+)$#', $ranges, $matches)) {
            throw new \RuntimeException('invalid ranges: ' . $ranges);
        }
        $this->pre  = ['from' => (int)$matches[1], 'to' => (int)$matches[2]];
        $this->post = ['from' => (int)$matches[3], 'to' => (int)$matches[4]];
    }
16924
protected function prepareOffset(int $offset, int $total): int
    {
        if ($offset < -$total || $offset > $total - 1) {
            $message = sprintf('Offset (%d) out of range[%d, %d]', $offset, -$total, $total - 1);
            throw new DomainException($message);
        }

        if ($offset < 0) {
            $offset += $total;
        }

        return $offset;
    }
3321
public function setRows($rows = []) {

        if (!empty($this->cols)) {
            if (count($rows[0]) < 1) {
                throw new \Exception('Expected 2 dimensional array for rows');
            } elseif (count($this->cols) != 0 && count($this->cols) != count($rows[0])) {
                throw new \Exception('No of cols must equivelent to no heads in rows');
            }
        }
        $this->rows = $rows;
        return $this;
    }
1348150
public function getCellsList($offset, $count)
    {
        //check whether workshett name is set or not
        if ($this->worksheetName == '')
            throw new Exception('Worksheet name not specified');
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() .
            '/worksheets/' . $this->worksheetName . '/cells?offset=' .
            $offset . '&count=' . $count;
        $signedURI = Utils::sign($strURI);
        $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
        $json = json_decode($responseStream);
        $listCells = array();
        foreach ($json->Cells->CellList as $cell) {
            $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() .
                '/worksheets/' . $this->worksheetName . '/cells' . $cell->link->Href;
            $signedURI = Utils::sign($strURI);
            $responseStream = Utils::processCommand($signedURI, 'GET', '', '');
            $json = json_decode($responseStream);
            array_push($listCells, $json->Cell);
        }
        return $listCells;

    }
1069434
public function createSheet(
        array $headers,
        array $rows,
        string $title
    ): void {
        // Check if we are setting any custom column widths.
        if ($this->hasColumnWidths()) {
            // We have a numeric index array, so create an array of letters that we can use to map to Excel columns.
            // e.g. 0 = A, 3 = D, etc.
            $columns = range('A', 'Z');

            $this->builder->applyColumnWidths($columns, $this->getColumnWidths());
        }

        // Style settings for agent headers
        $style = $this->builder->buildRowStyle([
            'alignment' => BuilderInterface::ALIGNMENT_CENTRE,
            'font'      => [
                'color' => [
                    'rgb' => BuilderInterface::COLOUR_BLACK_RGB,
                ],
                'bold'  => true,
            ],
        ]);

        // Build column headers.
        $this->builder->buildHeaderRow($headers, $style);

        // Build all the rows now.
        $this->builder->buildRows($rows);

        // If no column widths are specified, then simply auto-size all columns.
        if (!$this->hasColumnWidths()) {
            $this->builder->autoSizeColumns($rows[0]);
        }

        // Rename sheet.
        $this->builder->setSheetTitle($title);
    }
1348853
public function setActiveWorksheet($worksheet)
    {
        if(is_string($worksheet)){
            $worksheet = $this->worksheets[md5($worksheet)];
        }
        $this->active_worksheet = $worksheet;
        return $worksheet;

    }
1333569
public function setTotal($total) {
		if ($total instanceof Builder) {
			$this->_total = intval($total->count());
			return $this;
		}
		$this->_total = intval($total);
		return $this;
	}
425354
public function generateXlsFile(array $protoFunctions, string $path): void
    {
        $spreadsheet = new Spreadsheet();
        $numb = 1;

        $sheet = $spreadsheet->getActiveSheet();
        $sheet->setCellValue('A1', 'Function name');
        $sheet->setCellValue('B1', 'Status');

        foreach ($protoFunctions as $protoFunction) {
            if ($protoFunction) {
                if (strpos($protoFunction, '=') === false && strpos($protoFunction, 'json') === false) {
                    $status = 'classic';
                } elseif (strpos($protoFunction, 'json')) {
                    $status = 'json';
                } else {
                    $status = 'opt';
                }
                $sheet->setCellValue('A'.$numb, $protoFunction);
                $sheet->setCellValue('B'.$numb++, $status);
            }
        }
        $writer = new Xlsx($spreadsheet);
        $writer->save($path);
    }
579972
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;
    }
935082
public static function setSheet($sheet=0, $title=NULL, $normalizeTitle=false)
    {
        self::resetSheet();

        if (is_object($sheet)) {
            
            self::$_objSheet = &$sheet;
        } 
        elseif (is_numeric($sheet) && $sheet>=0 && self::$_objSpreadsheet) {

            /* Sheets Check */
            $sheetCount = self::$_objSpreadsheet->getSheetCount();
            if ($sheet >= $sheetCount) {
                for ($i=$sheetCount; $i <= $sheet; $i++) { 
                    self::$_objSpreadsheet->createSheet($i);
                }
            }
            // Select sheet
            self::$_objSheet = self::$_objSpreadsheet->setActiveSheetIndex($sheet);
        }
        elseif (is_null($sheet) && self::$_objSpreadsheet) {
            // Auto create a sheet without index
            self::setSheet(self::getSheetCount());
        }
        else {
            throw new Exception("Invalid or empty PhpSpreadsheet Object for setting sheet", 400);
        }

        // Sheet Title
        if ($title) {
            // Auto-normalize title rule 
            if ($normalizeTitle) {
                /**
                 * @see PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
                 */
                // Some of the printable ASCII characters are invalid:  * : / \ ? [ ]
                $title = str_replace(self::$_invalidCharacters, '', $title);
                // Maximum 31 characters allowed for sheet title
                $title = mb_substr($title, 0, 31);
            }

            self::$_objSheet->setTitle($title);
        }

        return new static();
    }
983156
public function write(
        array $data,
        string $sheet = ClientInterface::DEFAULT_SHEET,
        string $range = ClientInterface::DEFAULT_RANGE
    ): void {
        $this->doWrite($data, $this->file, $sheet, $range);
    }
518818
public function start_sheet($columns) {
        if ($this->sheettitle && $this->writer instanceof \Box\Spout\Writer\AbstractMultiSheetsWriter) {
            if ($this->renamecurrentsheet) {
                $sheet = $this->writer->getCurrentSheet();
                $this->renamecurrentsheet = false;
            } else {
                $sheet = $this->writer->addNewSheetAndMakeItCurrent();
            }
            $sheet->setName($this->sheettitle);
        }
        $this->writer->addRow(array_values((array)$columns));
    }
141892
private function sumTable($table)
    {
        $metadata = $table->getMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME);
        $enableCopyMetadata = false;

        foreach ($table->getRowsWithoutSummaryRow() as $row) {
            $this->sumRow($row, $enableCopyMetadata, $metadata);
        }

        $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);

        if ($summaryRow) {
            $this->sumRow($summaryRow, $enableCopyMetadata, $metadata);
        }
    }
182787
public void setTotal(int total) throws IllegalArgumentException {
    if(getProcessed() > total) {
      throw new IllegalArgumentException(getProcessed() + " exceeds total: " + total);
    }
    this.total = total;
  }
1323769
public function addToCounter($eventType, $count)
    {
        if (!isset($this->totalEvents[$eventType])) {
            $this->totalEvents[$eventType] = 0;
        }

        if (is_array($count)) {
            if (isset($count['total'])) {
                $this->totalEvents[$eventType] += $count['total'];
            } elseif ($this->isEngagementCount() && $this->groupUnit) {
                // Group counts across events by unit
                foreach ($count as $key => $data) {
                    if (!isset($this->totalEventsByUnit[$key])) {
                        $this->totalEventsByUnit[$key] = 0;
                    }
                    $this->totalEventsByUnit[$key] += (int) $data;
                    $this->totalEvents[$eventType] += (int) $data;
                }
            } else {
                $this->totalEvents[$eventType] = array_sum($count);
            }
        } else {
            $this->totalEvents[$eventType] += (int) $count;
        }
    }