提交的内容

This commit is contained in:
2025-05-12 15:45:02 +08:00
parent 629c4750da
commit b48c692775
3043 changed files with 34732 additions and 60810 deletions

View File

@ -261,7 +261,7 @@ class Extract
$delimiter = Functions::flattenArray($delimiter);
$quotedDelimiters = array_map(
function ($delimiter) {
return preg_quote($delimiter ?? '');
return preg_quote($delimiter ?? '', '/');
},
$delimiter
);
@ -270,7 +270,7 @@ class Extract
return '(' . $delimiters . ')';
}
return '(' . preg_quote($delimiter ?? '') . ')';
return '(' . preg_quote($delimiter ?? '', '/') . ')';
}
private static function matchFlags(int $matchMode): string

View File

@ -129,7 +129,7 @@ class Format
$format = Helpers::extractString($format);
if (!is_numeric($value) && Date::isDateTimeFormatCode($format)) {
$value = DateTimeExcel\DateValue::fromString($value);
$value = DateTimeExcel\DateValue::fromString($value) + DateTimeExcel\TimeValue::fromString($value);
}
return (string) NumberFormat::toFormattedString($value, $format);
@ -140,7 +140,7 @@ class Format
*
* @return mixed
*/
private static function convertValue($value)
private static function convertValue($value, bool $spacesMeanZero = false)
{
$value = $value ?? 0;
if (is_bool($value)) {
@ -150,6 +150,12 @@ class Format
throw new CalcExp(ExcelError::VALUE());
}
}
if (is_string($value)) {
$value = trim($value);
if ($spacesMeanZero && $value === '') {
$value = 0;
}
}
return $value;
}
@ -181,6 +187,9 @@ class Format
'',
trim($value, " \t\n\r\0\x0B" . StringHelper::getCurrencyCode())
);
if ($numberValue === '') {
return ExcelError::VALUE();
}
if (is_numeric($numberValue)) {
return (float) $numberValue;
}
@ -277,7 +286,7 @@ class Format
}
try {
$value = self::convertValue($value);
$value = self::convertValue($value, true);
$decimalSeparator = self::getDecimalSeparator($decimalSeparator);
$groupSeparator = self::getGroupSeparator($groupSeparator);
} catch (CalcExp $e) {
@ -285,12 +294,12 @@ class Format
}
if (!is_numeric($value)) {
$decimalPositions = preg_match_all('/' . preg_quote($decimalSeparator) . '/', $value, $matches, PREG_OFFSET_CAPTURE);
$decimalPositions = preg_match_all('/' . preg_quote($decimalSeparator, '/') . '/', $value, $matches, PREG_OFFSET_CAPTURE);
if ($decimalPositions > 1) {
return ExcelError::VALUE();
}
$decimalOffset = array_pop($matches[0])[1]; // @phpstan-ignore-line
if (strpos($value, $groupSeparator, $decimalOffset) !== false) {
$decimalOffset = array_pop($matches[0])[1] ?? null;
if ($decimalOffset === null || strpos($value, $groupSeparator, $decimalOffset) !== false) {
return ExcelError::VALUE();
}

View File

View File

View File

View File

@ -193,7 +193,7 @@ class Text
if (is_array($delimiter) && count($valueSet) > 1) {
$quotedDelimiters = array_map(
function ($delimiter) {
return preg_quote($delimiter ?? '');
return preg_quote($delimiter ?? '', '/');
},
$valueSet
);
@ -202,7 +202,7 @@ class Text
return '(' . $delimiters . ')';
}
return '(' . preg_quote(/** @scrutinizer ignore-type */ Functions::flattenSingleValue($delimiter)) . ')';
return '(' . preg_quote(/** @scrutinizer ignore-type */ Functions::flattenSingleValue($delimiter), '/') . ')';
}
private static function matchFlags(bool $matchMode): string

View File