Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Sep 27, 2022
1 parent 09af590 commit cf63392
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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'],
Expand Down
16 changes: 15 additions & 1 deletion src/Drivers/PhpSpreadsheetDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,20 +517,34 @@ 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']);
}

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']);
Expand Down
2 changes: 1 addition & 1 deletion src/Sheets/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit cf63392

Please sign in to comment.