A wrapper around the PhpSpreadsheet library to make consistently formatted spreadsheets.

@param array $rows
@param array $totals
@param string $sheetName
@param string $path
@param array $options

@return string
@throws \Exception
199682
public static function simple( array $rows = [], array $totals = [], string $sheetName = 'worksheet', string $path = '', array $options = [] ) {
        try {

            /**
             * @var Spreadsheet $spreadsheet
             */
            $spreadsheet = new Spreadsheet();
            $path        = self::getUniqueFilePath( $path );
            self::initializeFile( $path );
            self::setOptions( $spreadsheet, $options );
            self::setOrientationLandscape( $spreadsheet );
            self::setHeaderRow( $spreadsheet, $rows );
            self::setRows( $spreadsheet, $rows );
            self::setFooterTotals( $spreadsheet, $totals );
            self::setWorksheetTitle( $spreadsheet, $sheetName );
            self::writeSpreadsheet( $spreadsheet, $path );
        } catch ( \Exception $e ) {
            throw $e;
        }

        return $path;
    }
147961
public function mergeCells($startRow, $startColumn, $totalRows, $totalColumns)
    {
        if ($startRow == '')
            throw new Exception('Start Row not specified');
        
        if ($startColumn == '')
            throw new Exception('Start Column not specified');
        
        if ($totalRows == '')
            throw new Exception('Total Rows not specified');
        
        if ($totalColumns == '')
            throw new Exception('Total Columns not specified');
        
        //Build URI
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/worksheets/' . $this->worksheetName . 
                  '/cells/merge?startrow=' . $startRow . '&startcolumn=' . $startColumn .
                  '&totalrows=' . $totalRows . '&totalcolumns=' . $totalColumns;
        //Sign URI
        $signedURI = Utils::sign($strURI);
        
        //Send request and receive response
        $response = Utils::processCommand($signedURI, 'POST', '', '');
        $json = json_decode($response);
        if ($json->Code == 200) {
            $strURI = Product::$baseProductUri . '/storage/file/' . $this->getFileName();
            $signedURI = Utils::Sign($strURI);
            $responseStream = Utils::processCommand($signedURI, "GET", "", "");

            $outputPath = AsposeApp::$outPutLocation . $this->getFileName();
            Utils::saveFile($responseStream, $outputPath);
            return $outputPath;
        }    
        else
            return false;
    }
772083
public function export(array &$rows)
    {
        $config     = $this->getConfiguration('export');
        $fieldNames = isset($config['fields']) ? $config['fields'] : null;
        $result     = array();

        if ($fieldNames) {
            foreach ($rows as &$row) {
                $exportRow = array();
                foreach ($fieldNames as $fieldName => $fieldCode) {
                    $exportRow[ $fieldName ] = $this->evaluateField($row, $fieldCode);
                }
                $result[] = $exportRow;
            }
        } else {
            $result = &$rows;
        }

        return $result;
    }
873817
protected function newRow($total, $index, $record, $attributes, $content)
    {
        return HTML::createTag(
            'tr',
            $attributes,
            $content
        );
    }
324169
public function readCell($column, $row, $worksheetName = '') {
    
    return ($row >= $this->firstRow && $row <= $this->lastRow &&
            array_key_exists($column, $this->range));
  }
1023757
private function parseS3CmdListRow($row)
    {
        $columns = explode(' ', preg_replace('/\s+/', ' ', $row));

        if (4 !== count($columns)) {
            throw new \RuntimeException(sprintf('Error processing result: %s', $row));
        }

        return new Backup($columns[3], $columns[2], new \DateTime(sprintf('%s %s', $columns[0], $columns[1])));
    }
187924
function _calculateTotals() {
        if (empty($this->_calculateTotals)) {
            return;
        }

        $this->addSeparator();

        $totals = array();
        foreach ($this->_data as $row) {
            if (is_array($row)) {
                foreach ($this->_calculateTotals as $columnID) {
                    $totals[$columnID] += $row[$columnID];
                }
            }
        }

        $this->_data[] = $totals;
        $this->_updateRowsCols();
    }
126557
public function setHeaderRow(array $row)
    {
        if (null === $this->nbColumns) {
            $this->nbColumns = count($row);
        } elseif (count($row) !== $this->nbColumns) {
            throw new LogicException(sprintf(
                'Expected the header row to contain %s cells, but got %s.',
                $this->nbColumns,
                count($row)
            ));
        }

        $this->headerRow = array_values($row);

        return $this;
    }
926722
protected function row(Row $row, array $cells)
	{
		$html = '<tr';
		$this->addAttributes($html, $row->getAttributes());
		$html .= '>' . implode('', $cells) . '</tr>';

		return $html;
	}
1011317
public function get(string $path, array $row): ?string
    {
        if (!$this->supports($row)) {
            return null;
        }

        $content = $row[$this->colName];
        $chunks  = explode('.', $path);
        if (!array_key_exists($chunks[0], $content)) {
            return null;
        }
        $content = $content[$chunks[0]];

        if (null === ($extractor = $this->extractors[$chunks[1]] ?? null)) {
            throw new \InvalidArgumentException('Sub extractor ' . $chunks[1] . ' not found');
        }

        switch (true) {
            case $extractor instanceof MultiStringExtractorInterface:
                return $extractor->get(implode('.', \array_slice($chunks, 2)), $content);
            case $extractor instanceof StringExtractorInterface:
                return $extractor->get($content);
            default:
        }

        throw new \InvalidArgumentException('Unknown extractor type ' . \get_class($extractor));
    }
536194
private function filterColumns(array $rows, array $header, array $columnsToDisplay)
    {
        if (empty($columnsToDisplay)) {
            return $rows;
        }

        // The available columns are all the (lower-cased) values and string
        // keys in $header.
        $availableColumns = [];
        foreach ($header as $key => $column) {
            $columnName = is_string($key) ? $key : $column;
            $availableColumns[strtolower($columnName)] = $key;
        }

        // Validate the column names.
        foreach ($columnsToDisplay as &$columnName) {
            $columnNameLowered = strtolower($columnName);
            if (!isset($availableColumns[$columnNameLowered])) {
                throw new InvalidArgumentException(
                    sprintf('Column not found: %s (available columns: %s)', $columnName, implode(', ', array_keys($availableColumns)))
                );
            }
            $columnName = $columnNameLowered;
        }

        // Filter the rows for keys matching those in $availableColumns. If a
        // key doesn't exist in a row, then the cell will be an empty string.
        $newRows = [];
        foreach ($rows as $row) {
            $newRow = [];
            foreach ($columnsToDisplay as $columnNameLowered) {
                $key = $availableColumns[$columnNameLowered];
                $newRow[] = array_key_exists($key, $row) ? $row[$key] : '';
            }
            $newRows[] = $newRow;
        }

        return $newRows;
    }
468233
protected function _render(array $row, $widths, $options = [])
    {
        if (count($row) === 0) {
            return;
        }

        $out = '';
        foreach (array_values($row) as $i => $column) {
            $pad = $widths[$i] - $this->_cellWidth($column);
            if (!empty($options['style'])) {
                $column = $this->_addStyle($column, $options['style']);
            }
            $out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
        }
        $out .= '|';
        $this->_io->out($out);
    }
1131444
public function readRow($rowKey, array $options = [])
    {
        return $this->readRows(
            ['rowKeys' => [$rowKey]] + $options + $this->options
        )
            ->readAll()
            ->current();
    }
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);
    }
607533
private function describeCount($rows = null)
    {
        if ($rows === null) {
            $rows = $this->fetchTargetRows();
        }

        if (!is_array($rows) && !($rows instanceof Traversable)) {
            throw new InvalidArgumentException(
                sprintf(
                    'The rows must be iterable; received %s',
                    is_object($rows) ? get_class($rows) : gettype($rows)
                )
            );
        }

        $cli   = $this->climate();
        $model = $this->targetModel();

        if (is_array($rows) || $rows instanceof Countable) {
            $count = count($rows);
        } elseif ($rows instanceof PDOStatement) {
            $count = $rows->rowCount();
        } else {
            $count = iterator_count($rows);
        }

        if ($count === 0) {
            $cli->comment('The object table is empty.');
            $cli->comment(
                sprintf('Only changing `%s` column.', $model->key())
            );

            return false;
        } elseif ($count === 1) {
            if (!$this->quiet()) {
                $cli->comment('The object table has 1 row.');
            }
        } else {
            if (!$this->quiet()) {
                $cli->comment(
                    sprintf('The object table has %s rows.', $count)
                );
            }
        }

        return true;
    }
1262614
public static function dbRow($tname, $options=array()) {

        try {
            $row = array();
            $defArray = ['type'=>'assoc', 'all'=>'all'];
            // options array will override the default array
            $coptions = array_merge($defArray, $options);
            $rows = self::select($tname, $coptions);
            if (!empty($rows)) {
                $row = array_shift($rows); // get top one array
            }
            return $row;
        } catch (Exception $e) {
            echo $e->getTraceAsString();
        }        
    }
796296
public function set(string $path, array &$row, string $value = null): void
    {
        if (!$this->supports($row)) {
            return;
        }
        if (!array_key_exists($this->colName, $row)) {
            $row[$this->colName] = [];
        }

        $content = &$row[$this->colName];
        $chunks  = explode('.', $path);
        if (!array_key_exists($chunks[0], $content)) {
            $content[$chunks[0]] = [];
        }
        $content = &$content[$chunks[0]];

        if (null === ($extractor = $this->extractors[$chunks[1]] ?? null)) {
            throw new \InvalidArgumentException('Sub extractor ' . $chunks[1] . ' not found');
        }

        switch (true) {
            case $extractor instanceof MultiStringExtractorInterface:
                $extractor->set(implode('.', \array_slice($chunks, 2)), $content, $value);
                return;
            case $extractor instanceof StringExtractorInterface:
                $extractor->set($content, $value);
                return;
            default:
        }

        throw new \InvalidArgumentException('Unknown extractor type ' . \get_class($extractor));
    }