Initial extraction of method getCellXml from addRow (#302)
This commit is contained in:
parent
277c353984
commit
5e7a1745ac
@ -134,9 +134,36 @@ EOD;
|
|||||||
$rowXML = '<row r="' . $rowIndex . '" spans="1:' . $numCells . '">';
|
$rowXML = '<row r="' . $rowIndex . '" spans="1:' . $numCells . '">';
|
||||||
|
|
||||||
foreach($dataRow as $cellValue) {
|
foreach($dataRow as $cellValue) {
|
||||||
|
$rowXML .= $this->getCellXml($rowIndex, $cellNumber, $cellValue, $style->getId());
|
||||||
|
$cellNumber++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rowXML .= '</row>';
|
||||||
|
|
||||||
|
$wasWriteSuccessful = fwrite($this->sheetFilePointer, $rowXML);
|
||||||
|
if ($wasWriteSuccessful === false) {
|
||||||
|
throw new IOException("Unable to write data in {$this->worksheetFilePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// only update the count if the write worked
|
||||||
|
$this->lastWrittenRowIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build and return xml for a single cell.
|
||||||
|
*
|
||||||
|
* @param int $rowIndex
|
||||||
|
* @param int $cellNumber
|
||||||
|
* @param mixed $cellValue
|
||||||
|
* @param int $styleId
|
||||||
|
* @return string
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
private function getCellXml($rowIndex, $cellNumber, $cellValue, $styleId)
|
||||||
|
{
|
||||||
$columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber);
|
$columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber);
|
||||||
$cellXML = '<c r="' . $columnIndex . $rowIndex . '"';
|
$cellXML = '<c r="' . $columnIndex . $rowIndex . '"';
|
||||||
$cellXML .= ' s="' . $style->getId() . '"';
|
$cellXML .= ' s="' . $styleId . '"';
|
||||||
|
|
||||||
if (CellHelper::isNonEmptyString($cellValue)) {
|
if (CellHelper::isNonEmptyString($cellValue)) {
|
||||||
if ($this->shouldUseInlineStrings) {
|
if ($this->shouldUseInlineStrings) {
|
||||||
@ -156,19 +183,7 @@ EOD;
|
|||||||
throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue));
|
throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
$rowXML .= $cellXML;
|
return $cellXML;
|
||||||
$cellNumber++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$rowXML .= '</row>';
|
|
||||||
|
|
||||||
$wasWriteSuccessful = fwrite($this->sheetFilePointer, $rowXML);
|
|
||||||
if ($wasWriteSuccessful === false) {
|
|
||||||
throw new IOException("Unable to write data in {$this->worksheetFilePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// only update the count if the write worked
|
|
||||||
$this->lastWrittenRowIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user