Skip to content

Commit 2af0b66

Browse files
author
MarkBaker
committed
Read number formatting for Gnumeric... highlighted as not occurring when reading date values
1 parent fe901d1 commit 2af0b66

File tree

2 files changed

+49
-39
lines changed

2 files changed

+49
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
1313

1414
### Changed
1515

16-
- Nothing
16+
- Gnumeric Reader now loads number formatting for cells
1717

1818
### Deprecated
1919

src/PhpSpreadsheet/Reader/Gnumeric.php

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -300,44 +300,7 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
300300
}
301301
}
302302

303-
$ValueType = $cellAttributes->ValueType;
304-
$ExprID = (string) $cellAttributes->ExprID;
305-
$type = DataType::TYPE_FORMULA;
306-
if ($ExprID > '') {
307-
if (((string) $cell) > '') {
308-
$this->expressions[$ExprID] = [
309-
'column' => $cellAttributes->Col,
310-
'row' => $cellAttributes->Row,
311-
'formula' => (string) $cell,
312-
];
313-
} else {
314-
$expression = $this->expressions[$ExprID];
315-
316-
$cell = $this->referenceHelper->updateFormulaReferences(
317-
$expression['formula'],
318-
'A1',
319-
$cellAttributes->Col - $expression['column'],
320-
$cellAttributes->Row - $expression['row'],
321-
$worksheetName
322-
);
323-
}
324-
$type = DataType::TYPE_FORMULA;
325-
} else {
326-
$vtype = (string) $ValueType;
327-
if (array_key_exists($vtype, self::$mappings['dataType'])) {
328-
$type = self::$mappings['dataType'][$vtype];
329-
}
330-
if ($vtype === '20') { // Boolean
331-
$cell = $cell == 'TRUE';
332-
}
333-
}
334-
335-
$this->spreadsheet->getActiveSheet()->getCell($column . $row)->setValueExplicit((string) $cell, $type);
336-
if (isset($cellAttributes->ValueFormat)) {
337-
$this->spreadsheet->getActiveSheet()->getCell($column . $row)
338-
->getStyle()->getNumberFormat()
339-
->setFormatCode((string) $cellAttributes->ValueFormat);
340-
}
303+
$this->loadCell($cell, $worksheetName, $cellAttributes, $column, $row);
341304
}
342305

343306
if ($sheet->Styles !== null) {
@@ -536,4 +499,51 @@ private function parseRichText(string $is): RichText
536499

537500
return $value;
538501
}
502+
503+
private function loadCell(
504+
SimpleXMLElement $cell,
505+
string $worksheetName,
506+
SimpleXMLElement $cellAttributes,
507+
string $column,
508+
int $row
509+
): void {
510+
$ValueType = $cellAttributes->ValueType;
511+
$ExprID = (string) $cellAttributes->ExprID;
512+
$type = DataType::TYPE_FORMULA;
513+
if ($ExprID > '') {
514+
if (((string) $cell) > '') {
515+
$this->expressions[$ExprID] = [
516+
'column' => $cellAttributes->Col,
517+
'row' => $cellAttributes->Row,
518+
'formula' => (string) $cell,
519+
];
520+
} else {
521+
$expression = $this->expressions[$ExprID];
522+
523+
$cell = $this->referenceHelper->updateFormulaReferences(
524+
$expression['formula'],
525+
'A1',
526+
$cellAttributes->Col - $expression['column'],
527+
$cellAttributes->Row - $expression['row'],
528+
$worksheetName
529+
);
530+
}
531+
$type = DataType::TYPE_FORMULA;
532+
} else {
533+
$vtype = (string) $ValueType;
534+
if (array_key_exists($vtype, self::$mappings['dataType'])) {
535+
$type = self::$mappings['dataType'][$vtype];
536+
}
537+
if ($vtype === '20') { // Boolean
538+
$cell = $cell == 'TRUE';
539+
}
540+
}
541+
542+
$this->spreadsheet->getActiveSheet()->getCell($column . $row)->setValueExplicit((string) $cell, $type);
543+
if (isset($cellAttributes->ValueFormat)) {
544+
$this->spreadsheet->getActiveSheet()->getCell($column . $row)
545+
->getStyle()->getNumberFormat()
546+
->setFormatCode((string) $cellAttributes->ValueFormat);
547+
}
548+
}
539549
}

0 commit comments

Comments
 (0)