diff --git a/README.md b/README.md index 76afedf..e9f974c 100644 --- a/README.md +++ b/README.md @@ -192,13 +192,11 @@ $data = [ ]; (new \AnourValar\Office\SheetsService()) - ->hookLoad(function ($driver, string $templateFile, $templateFormat) - { + ->hookLoad(function ($driver, string $templateFile, $templateFormat) { // create empty document instead of using existing return $driver->create(); }) - ->hookBefore(function ($driver, array &$data) - { + ->hookBefore(function ($driver, array &$data) { // place markers on-fly $row = 1; foreach (array_keys($data) as $group) { @@ -299,8 +297,7 @@ $data = function () { // Save as XLSX (Excel) (new \AnourValar\Office\GridService()) - ->hookHeader(function (GridInterface $driver, mixed $header, $key, $column) - { + ->hookHeader(function (GridInterface $driver, mixed $header, $key, $column) { if (isset($header['width'])) { $driver->setWidth($column, $header['width']); // column with fixed width } else { @@ -309,8 +306,7 @@ $data = function () { return $header['title']; }) - ->hookRow(function (GridInterface $driver, mixed $row, $key) - { + ->hookRow(function (GridInterface $driver, mixed $row, $key) { return [ $row['name'], $row['sales'], diff --git a/src/Drivers/PhpSpreadsheetDriver.php b/src/Drivers/PhpSpreadsheetDriver.php index 4164cec..8ca8d40 100644 --- a/src/Drivers/PhpSpreadsheetDriver.php +++ b/src/Drivers/PhpSpreadsheetDriver.php @@ -517,9 +517,17 @@ public function insertImage(string $filename, string $cell, array $options = []) { $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); - $drawing->setPath($filename); // put your path and image here + if (isset($options['base64'])) { + $filename = 'data:image/' . $options['base64'] . ';base64,' . base64_encode(file_get_contents($filename)); + } + + $drawing->setPath($filename); $drawing->setCoordinates($cell); + if (isset($options['coordinates2'])) { + $drawing->setCoordinates2($options['coordinates2']); + } + if (isset($options['name'])) { $drawing->setName($options['name']); } @@ -527,10 +535,16 @@ public function insertImage(string $filename, string $cell, array $options = []) if (isset($options['offset_x'])) { $drawing->setOffsetX($options['offset_x']); } + if (isset($options['offset_x2'])) { + $drawing->setOffsetX2($options['offset_x2']); + } if (isset($options['offset_y'])) { $drawing->setOffsetY($options['offset_y']); } + if (isset($options['offset_y2'])) { + $drawing->setOffsetY2($options['offset_y2']); + } if (isset($options['rotation'])) { $drawing->setRotation($options['rotation']); diff --git a/src/Sheets/Parser.php b/src/Sheets/Parser.php index 4eaceb0..65a64eb 100644 --- a/src/Sheets/Parser.php +++ b/src/Sheets/Parser.php @@ -299,7 +299,7 @@ protected function calculateDataSchema(array &$values, array &$data, array &$mer if ($additionRows) { foreach ($columns as $currKey => $currValue) { - $hasMarker = preg_match('#\[([a-z][a-z\d\.\_]+)\]#i', $currValue); + $hasMarker = preg_match('#\[([a-z][a-z\d\.\_]+)\]#i', (string) $currValue); foreach ($mergeCells as $item) { if ($currKey.$originalRow == $item[0][0].$item[0][1]) {