Box\Spout\Writer\ODS\Internal\Worksheet::addRow PHP Method

addRow() public method

Adds data to the worksheet.
public addRow ( array $dataRow, Style $style ) : void
$dataRow array Array containing data to be written. Cannot be empty. Example $dataRow = ['data1', 1234, null, '', 'data5'];
$style Box\Spout\Writer\Style\Style Style to be applied to the row. NULL means use default style.
return void
    public function addRow($dataRow, $style)
    {
        // $dataRow can be an associative array. We need to transform
        // it into a regular array, as we'll use the numeric indexes.
        $dataRowWithNumericIndexes = array_values($dataRow);
        $styleIndex = $style->getId() + 1;
        // 1-based
        $cellsCount = count($dataRow);
        $this->maxNumColumns = max($this->maxNumColumns, $cellsCount);
        $data = '<table:table-row table:style-name="ro1">';
        $currentCellIndex = 0;
        $nextCellIndex = 1;
        for ($i = 0; $i < $cellsCount; $i++) {
            $currentCellValue = $dataRowWithNumericIndexes[$currentCellIndex];
            // Using isset here because it is way faster than array_key_exists...
            if (!isset($dataRowWithNumericIndexes[$nextCellIndex]) || $currentCellValue !== $dataRowWithNumericIndexes[$nextCellIndex]) {
                $numTimesValueRepeated = $nextCellIndex - $currentCellIndex;
                $data .= $this->getCellXML($currentCellValue, $styleIndex, $numTimesValueRepeated);
                $currentCellIndex = $nextCellIndex;
            }
            $nextCellIndex++;
        }
        $data .= '</table:table-row>';
        $wasWriteSuccessful = fwrite($this->sheetFilePointer, $data);
        if ($wasWriteSuccessful === false) {
            throw new IOException("Unable to write data in {$this->worksheetFilePath}");
        }
        // only update the count if the write worked
        $this->lastWrittenRowIndex++;
    }