Resolve issues introduced during resolution of merge conflicts from master

minor refactoring
This commit is contained in:
MarkBaker
2022-02-26 17:52:01 +01:00
parent 45a770a3fc
commit 5672bd8df1
5 changed files with 74 additions and 103 deletions
+5 -10
View File
@@ -655,6 +655,11 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/Functions.php
-
message: "#^Cannot use array destructuring on array\\<string\\>\\|string\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Information/Value.php
-
message: "#^Cannot call method getCell\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
count: 2
@@ -2210,16 +2215,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Ods.php
-
message: "#^Parameter \\#1 \\$settings of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\:\\:lookForActiveSheet\\(\\) expects DOMElement, DOMElement\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Ods.php
-
message: "#^Parameter \\#1 \\$settings of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\:\\:lookForSelectedCells\\(\\) expects DOMElement, DOMElement\\|null given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Ods.php
-
message: "#^While loop condition is always true\\.$#"
count: 2
+1
View File
@@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Collection\Cells;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\CellStyleAssessor;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Style;
-32
View File
@@ -2,10 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Cell;
use DateTime;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class DataType
@@ -86,33 +83,4 @@ class DataType
return $value;
}
/**
* @param mixed $value
*
* @return float|int
*/
public static function checkIsoDate($value)
{
if (!is_string($value)) {
throw new Exception('Non-string supplied for datatype Date');
}
try {
$date = new DateTime($value);
$newValue = SharedDate::PHPToExcel($date);
} catch (\Exception $e) {
throw new Exception("Invalid string $value supplied for datatype Date");
}
if ($newValue === false) {
throw new Exception("Invalid string $value supplied for datatype Date");
}
if (preg_match('/^\\d\\d:\\d\\d:\\d\\d/', $value) == 1) {
$newValue = fmod($newValue, 1.0);
}
return $newValue;
}
}
+47 -44
View File
@@ -512,14 +512,10 @@ class Ods extends BaseReader
$dataValue = null;
}
$isArrayFormula = false;
$arrayFormulaRange = null;
if ($hasCalculatedValue) {
$type = DataType::TYPE_FORMULA;
$cellDataFormula = substr($cellDataFormula, strpos($cellDataFormula, ':=') + 1);
$cellDataFormula = $this->convertToExcelFormulaValue($cellDataFormula);
$isArrayFormula = (!empty($arrayAttributeRows) && !empty($arrayAttributeColumns));
$arrayFormulaRange = null;
}
if ($cellData->hasAttributeNS($tableNs, 'number-columns-repeated')) {
@@ -544,6 +540,7 @@ class Ods extends BaseReader
// Set value
if ($hasCalculatedValue) {
$arrayFormulaRange = null;
$isArrayFormula = (!empty($arrayAttributeRows) && !empty($arrayAttributeColumns));
if ($isArrayFormula === true) {
$arrayFormulaRange = $columnID . $rID;
$arrayAttributeRows = (int) $arrayAttributeRows;
@@ -568,17 +565,10 @@ class Ods extends BaseReader
}
// Set other properties
if ($formatting !== null) {
$spreadsheet->getActiveSheet()
->getStyle($columnID . $rID)
->getNumberFormat()
->setFormatCode($formatting);
} else {
$spreadsheet->getActiveSheet()
->getStyle($columnID . $rID)
->getNumberFormat()
->setFormatCode(NumberFormat::FORMAT_GENERAL);
}
$spreadsheet->getActiveSheet()
->getStyle($columnID . $rID)
->getNumberFormat()
->setFormatCode($formatting ?? NumberFormat::FORMAT_GENERAL);
if ($hyperlink !== null) {
$cell->getHyperlink()
@@ -590,31 +580,7 @@ class Ods extends BaseReader
}
// Merged cells
if (
$cellData->hasAttributeNS($tableNs, 'number-columns-spanned')
|| $cellData->hasAttributeNS($tableNs, 'number-rows-spanned')
) {
if (($type !== DataType::TYPE_NULL) || (!$this->readDataOnly)) {
$columnTo = $columnID;
if ($cellData->hasAttributeNS($tableNs, 'number-columns-spanned')) {
$columnIndex = Coordinate::columnIndexFromString($columnID);
$columnIndex += (int) $cellData->getAttributeNS($tableNs, 'number-columns-spanned');
$columnIndex -= 2;
$columnTo = Coordinate::stringFromColumnIndex($columnIndex + 1);
}
$rowTo = $rowID;
if ($cellData->hasAttributeNS($tableNs, 'number-rows-spanned')) {
$rowTo = $rowTo + (int) $cellData->getAttributeNS($tableNs, 'number-rows-spanned') - 1;
}
$cellRange = $columnID . $rowID . ':' . $columnTo . $rowTo;
$spreadsheet->getActiveSheet()->mergeCells($cellRange);
}
}
$this->processMergedCells($cellData, $tableNs, $type, $columnID, $rowID, $spreadsheet);
++$columnID;
}
@@ -653,11 +619,13 @@ class Ods extends BaseReader
$officeNs = $dom->lookupNamespaceUri('office');
$settings = $dom->getElementsByTagNameNS($officeNs, 'settings')
->item(0);
$this->lookForActiveSheet($settings, $spreadsheet, $configNs);
$this->lookForSelectedCells($settings, $spreadsheet, $configNs);
if ($settings !== null) {
$this->activeSheet($settings, $spreadsheet, $configNs);
$this->selectedCells($settings, $spreadsheet, $configNs);
}
}
private function lookForActiveSheet(DOMElement $settings, Spreadsheet $spreadsheet, string $configNs): void
private function activeSheet(DOMElement $settings, Spreadsheet $spreadsheet, string $configNs): void
{
/** @var DOMElement $t */
foreach ($settings->getElementsByTagNameNS($configNs, 'config-item') as $t) {
@@ -673,7 +641,7 @@ class Ods extends BaseReader
}
}
private function lookForSelectedCells(DOMElement $settings, Spreadsheet $spreadsheet, string $configNs): void
private function selectedCells(DOMElement $settings, Spreadsheet $spreadsheet, string $configNs): void
{
/** @var DOMElement $t */
foreach ($settings->getElementsByTagNameNS($configNs, 'config-item-map-named') as $t) {
@@ -785,4 +753,39 @@ class Ods extends BaseReader
return $excelFormula;
}
private function processMergedCells(
DOMElement $cellData,
string $tableNs,
string $type,
string $columnID,
int $rowID,
Spreadsheet $spreadsheet
): void {
if (
$cellData->hasAttributeNS($tableNs, 'number-columns-spanned')
|| $cellData->hasAttributeNS($tableNs, 'number-rows-spanned')
) {
if (($type !== DataType::TYPE_NULL) || ($this->readDataOnly === false)) {
$columnTo = $columnID;
if ($cellData->hasAttributeNS($tableNs, 'number-columns-spanned')) {
$columnIndex = Coordinate::columnIndexFromString($columnID);
$columnIndex += (int) $cellData->getAttributeNS($tableNs, 'number-columns-spanned');
$columnIndex -= 2;
$columnTo = Coordinate::stringFromColumnIndex($columnIndex + 1);
}
$rowTo = $rowID;
if ($cellData->hasAttributeNS($tableNs, 'number-rows-spanned')) {
$rowTo = $rowTo + (int) $cellData->getAttributeNS($tableNs, 'number-rows-spanned') - 1;
}
$cellRange = $columnID . $rowID . ':' . $columnTo . $rowTo;
$spreadsheet->getActiveSheet()->mergeCells($cellRange);
}
}
}
}
+21 -17
View File
@@ -5,11 +5,11 @@ namespace PhpOffice\PhpSpreadsheet\Shared;
use DateTime;
use DateTimeInterface;
use DateTimeZone;
use Exception;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
@@ -75,10 +75,7 @@ class Date
*/
public static function setExcelCalendar($baseYear)
{
if (
($baseYear == self::CALENDAR_WINDOWS_1900) ||
($baseYear == self::CALENDAR_MAC_1904)
) {
if (($baseYear == self::CALENDAR_WINDOWS_1900) || ($baseYear == self::CALENDAR_MAC_1904)) {
self::$excelCalendar = $baseYear;
return true;
@@ -168,19 +165,23 @@ class Date
public static function convertIsoDate($value)
{
if (!is_string($value)) {
throw new Exception('Non-string value supplied for Iso Date conversion');
throw new PhpSpreadsheetException('Non-string value supplied for Iso Date conversion');
}
$date = new DateTime($value);
try {
$date = new DateTime($value);
} catch (Exception $e) {
throw new PhpSpreadsheetException("Invalid string $value supplied for datatype Date");
}
$dateErrors = DateTime::getLastErrors();
if (is_array($dateErrors) && ($dateErrors['warning_count'] > 0 || $dateErrors['error_count'] > 0)) {
throw new Exception("Invalid string $value supplied for datatype Date");
throw new PhpSpreadsheetException("Invalid string $value supplied for datatype Date");
}
$newValue = SharedDate::PHPToExcel($date);
if ($newValue === false) {
throw new Exception("Invalid string $value supplied for datatype Date");
throw new PhpSpreadsheetException("Invalid string $value supplied for datatype Date");
}
if (preg_match('/^\\d\\d:\\d\\d:\\d\\d/', $value) == 1) {
@@ -194,9 +195,9 @@ class Date
* Convert a MS serialized datetime value from Excel to a PHP Date/Time object.
*
* @param float|int $excelTimestamp MS Excel serialized date/time value
* @param null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp,
* if you don't want to treat it as a UTC value
* Use the default (UTC) unless you absolutely need a conversion
* @param null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp
* if you don't want to treat it as a UTC value
* Use the default (UTC) unless you absolutely need a conversion
*
* @return DateTime PHP date/time object
*/
@@ -211,7 +212,9 @@ class Date
// MS Excel calendar base dates
if (self::$excelCalendar == self::CALENDAR_WINDOWS_1900) {
// Allow adjustment for 1900 Leap Year in MS Excel
$baseDate = ($excelTimestamp < 60) ? new DateTime('1899-12-31', $timeZone) : new DateTime('1899-12-30', $timeZone);
$baseDate = ($excelTimestamp < 60)
? new DateTime('1899-12-31', $timeZone)
: new DateTime('1899-12-30', $timeZone);
} else {
$baseDate = new DateTime('1904-01-01', $timeZone);
}
@@ -243,9 +246,9 @@ class Date
* They are not Y2038-safe on a 32-bit system, and have no timezone info.
*
* @param float|int $excelTimestamp MS Excel serialized date/time value
* @param null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp,
* if you don't want to treat it as a UTC value
* Use the default (UTC) unless you absolutely need a conversion
* @param null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp
* if you don't want to treat it as a UTC value
* Use the default (UTC) unless you absolutely need a conversion
*
* @return int Unix timetamp for this date/time
*/
@@ -527,7 +530,8 @@ class Date
*
* @param string $day Day number with an ordinal
*
* @return int|string The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric
* @return int|string The integer value with any ordinal stripped,
* or the original string argument if it isn't a valid numeric
*/
public static function dayStringToNumber($day)
{