Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Apr 12, 2023
1 parent c687662 commit 86218a8
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 109 deletions.
20 changes: 20 additions & 0 deletions src/Drivers/PhpSpreadsheetDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,26 @@ public function copyStyleWithoutFormat(string $cellFrom, string $rangeTo, bool $
return $this;
}

/**
* Find a cell with the value
*
* @param mixed $value
* @param bool $strict
* @return array|null
*/
public function findCell($value, bool $strict = false): ?array
{
foreach ($this->getValues(null) as $row => $rowData) {
foreach ($rowData as $column => $columnData) {
if (($strict && $columnData === $value) || (! $strict && $columnData == $value)) {
return [$column, $row];
}
}
}

return null;
}

/**
* Set custom style for the range of cells
*
Expand Down
16 changes: 5 additions & 11 deletions src/Sheets/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ protected function calculateDataSchema(array &$values, array &$data, array &$mer
foreach ($mergeMapX as $mergeItemX) {
$curr++;

$schema->copyStyle($mergeItemX.($row + $shift), $curr.($row + $shift));
$schema->copyWidth($mergeItemX, $curr);
}

Expand All @@ -307,7 +306,7 @@ protected function calculateDataSchema(array &$values, array &$data, array &$mer
$hasMarker = preg_match('#\[([a-z][a-z\d\.\_]+)\]#iS', (string) $currValue);

foreach ($mergeCells as $item) {
if ($currKey.$originalRow == $item[0][0].$item[0][1]) {
if ($currKey.$originalRow == $item[0][0].$item[0][1] && $item[0][1] != $item[1][1]) {
if (! $hasMarker) {
unset($columns[$currKey]);
continue;
Expand Down Expand Up @@ -346,11 +345,6 @@ protected function calculateDataSchema(array &$values, array &$data, array &$mer
$schema->mergeCells(
sprintf('%s%s:%s%s', $item[0][0], ($row + $shift), $item[1][0], ($row + $shift + $diff))
);

while ($item[0][0] < $item[1][0]) {
$item[0][0]++;
$schema->copyStyle($item[0][0].$item[0][1], $item[0][0].($row + $shift));
}
}
}
}
Expand Down Expand Up @@ -709,11 +703,11 @@ private function increment(string $markerName, bool $first, int $shift = 1): ?st
private function increments(string $value, bool $first, int $shift = 1): ?string
{
return preg_replace_callback(
'#\[([a-z][a-z\d\.\_]+)\]#iS',
'#\[(\$?\!\s*|\$?\=\s*)?([a-z][a-z\d\.\_]+)\]#iS',
function ($patterns) use ($first, $shift) {
$patterns[1] = $this->increment($patterns[1], $first, $shift);
if ($patterns[1]) {
return '[' . $patterns[1] . ']';
$patterns[2] = $this->increment($patterns[2], $first, $shift);
if ($patterns[2]) {
return '[' . $patterns[1] . $patterns[2] . ']';
}

return $patterns[0];
Expand Down
Loading

0 comments on commit 86218a8

Please sign in to comment.