8000 update · laravel-enso/data-import@b4443de · GitHub
[go: up one dir, main page]

Skip to content

Commit b4443de

Browse files
committed
update
1 parent cf9374b commit b4443de

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/Services/Importers/Sheet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private function prepare(): self
8080
private function addRow(): void
8181
{
8282
$cells = $this->iterator->current()->getCells();
83+
8384
$row = Sanitize::cells($cells, $this->rowLength);
8485
$this->chunk->add($row);
8586

src/Services/Sanitizers/Sanitize.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Collection;
88
use Illuminate\Support\Str;
99
use OpenSpout\Common\Entity\Cell;
10+
use OpenSpout\Common\Entity\Cell\FormulaCell;
1011
use OpenSpout\Common\Entity\Row;
1112

1213
class Sanitize
@@ -25,7 +26,7 @@ public static function sheets(Collection $sheets): Collection
2526
public static function cells(array $cells, int $length): array
2627
{
2728
return Collection::wrap($cells)
28-
->map(fn ($cell) => self::cell($cell->getValue()))
29+
->map(fn ($cell) => self::cell($cell))
2930
->slice(0, $length)
3031
->pad($length, null)
3132
->toArray();
@@ -36,24 +37,28 @@ public static function name(string $name): string
3637
return Str::of($name)->lower()->snake();
3738
}
3839

39-
private static function cell($cell)
40+
private static function cell(Cell $cell)
4041
{
41-
if ($cell instanceof DateTime) {
42-
return Carbon::instance($cell)->toDateTimeString();
42+
$value = $cell instanceof FormulaCell
43+
? $cell->getComputedValue()
44+
: $cell->getValue();
45+
46+
if ($value instanceof DateTime) {
47+
return Carbon::instance($value)->toDateTimeString();
4348
}
4449

45-
if (is_string($cell)) {
46-
$cell = Str::of($cell)->trim();
50+
if (is_string($value)) {
51+
$value = Str::of($value)->trim();
4752
$to = 'UTF-8';
48-
$from = mb_detect_encoding($cell, ['auto']);
53+
$from = mb_detect_encoding($value, ['auto']);
4954

5055
if (! $from) {
51-
$cell = '';
56+
$value = '';
5257
} elseif ($from !== $to) {
53-
$cell = mb_convert_encoding($cell, $to, $from);
58+
$value = mb_convert_encoding($value, $to, $from);
5459
}
5560
}
5661

57-
return $cell === '' ? null : $cell;
62+
return $value === '' ? null : $value;
5863
}
5964
}

0 commit comments

Comments
 (0)
0