Merge b7831cc93313a0e56186df41d11c9bdcfb881bae into 538f6109ada0cad7e49d191e886b1f3ceda4ffa6
This commit is contained in:
commit
101583f41e
14
src/Spout/Writer/Exception/InvalidDataException.php
Normal file
14
src/Spout/Writer/Exception/InvalidDataException.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Box\Spout\Writer\Exception;
|
||||||
|
|
||||||
|
use Box\Spout\Common\Exception\SpoutException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InvalidDataException
|
||||||
|
*
|
||||||
|
* @package Box\Spout\Writer\Exception
|
||||||
|
*/
|
||||||
|
class InvalidDataException extends SpoutException
|
||||||
|
{
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace Box\Spout\Writer\Internal\XLSX;
|
namespace Box\Spout\Writer\Internal\XLSX;
|
||||||
|
|
||||||
use Box\Spout\Common\Exception\IOException;
|
use Box\Spout\Common\Exception\IOException;
|
||||||
|
use Box\Spout\Writer\Exception\InvalidDataException;
|
||||||
use Box\Spout\Writer\Helper\XLSX\CellHelper;
|
use Box\Spout\Writer\Helper\XLSX\CellHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,6 +120,7 @@ EOD;
|
|||||||
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
* Example $dataRow = ['data1', 1234, null, '', 'data5'];
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Box\Spout\Common\Exception\IOException If the data cannot be written
|
* @throws \Box\Spout\Common\Exception\IOException If the data cannot be written
|
||||||
|
* @throws \Box\Spout\Writer\Exception\InvalidDataException If input data are of invalid type
|
||||||
*/
|
*/
|
||||||
public function addRow($dataRow)
|
public function addRow($dataRow)
|
||||||
{
|
{
|
||||||
@ -132,19 +134,28 @@ EOD;
|
|||||||
$columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber);
|
$columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber);
|
||||||
$data .= ' <c r="' . $columnIndex . $rowIndex . '"';
|
$data .= ' <c r="' . $columnIndex . $rowIndex . '"';
|
||||||
|
|
||||||
if (empty($cellValue)) {
|
switch(true) {
|
||||||
$data .= '/>' . PHP_EOL;
|
case gettype($cellValue) === 'integer':
|
||||||
} else {
|
case gettype($cellValue) === 'boolean':
|
||||||
if (is_numeric($cellValue)) {
|
case gettype($cellValue) === 'float':
|
||||||
|
case gettype($cellValue) === 'double':
|
||||||
$data .= '><v>' . $cellValue . '</v></c>' . PHP_EOL;
|
$data .= '><v>' . $cellValue . '</v></c>' . PHP_EOL;
|
||||||
} else {
|
break;
|
||||||
|
case gettype($cellValue) === 'object' && method_exists($cellValue, '__toString'):
|
||||||
|
$cellValue = (string)$cellValue;
|
||||||
|
case gettype($cellValue) === 'string':
|
||||||
if ($this->shouldUseInlineStrings) {
|
if ($this->shouldUseInlineStrings) {
|
||||||
$data .= ' t="inlineStr"><is><t>' . $this->stringsEscaper->escape($cellValue) . '</t></is></c>' . PHP_EOL;
|
$data .= ' t="inlineStr"><is><t>' . $this->stringsEscaper->escape($cellValue) . '</t></is></c>' . PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
$sharedStringId = $this->sharedStringsHelper->writeString($cellValue);
|
$sharedStringId = $this->sharedStringsHelper->writeString($cellValue);
|
||||||
$data .= ' t="s"><v>' . $sharedStringId . '</v></c>' . PHP_EOL;
|
$data .= ' t="s"><v>' . $sharedStringId . '</v></c>' . PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
|
case empty($cellValue):
|
||||||
|
$data .= '/>' . PHP_EOL;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidDataException("Invalid data type " . gettype($cellValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
$cellNumber++;
|
$cellNumber++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user