Skip to content

Commit

Permalink
major update
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed May 27, 2022
1 parent fbd4e86 commit 4fc9973
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 317 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ composer require anourvalar/office
### To work with default driver - Phpspreadsheet is required:

```bash
composer require phpoffice/phpspreadsheet "^1.22"
composer require phpoffice/phpspreadsheet "^1.23"
```


Expand Down Expand Up @@ -57,7 +57,7 @@ $data = [
];

// Save as XLSX (Excel)
(new \AnourValar\Office\TemplateService())
(new \AnourValar\Office\SheetsService())
->generate(
'template1.xlsx', // path to template
$data // input data
Expand Down Expand Up @@ -116,9 +116,9 @@ $data = [
];

// Save as XLSX (Excel)
(new \AnourValar\Office\TemplateService())
(new \AnourValar\Office\SheetsService())
->generate('template2.xlsx', $data)
->saveAs('generated_document.xlsx'); // xlsx as save format is set by default
->saveAs('generated_document.xlsx'); // second argument (format) is optional
```

**generated_document.xlsx:**
Expand All @@ -134,32 +134,32 @@ $data = [
```php
$data = [
'foo' => 'Hello',
'bar' => function (\AnourValar\Office\Drivers\TemplateInterface $driver, $cell) {

'bar' => function (\AnourValar\Office\Drivers\SheetsInterface $driver, $cell) {
$driver->insertImage('logo.png', $cell, ['width' => 100, 'offset_y' => -45]);
return 'Logo!'; // replace marker "[bar]" with return value
}
];

(new \AnourValar\Office\TemplateService())
->hookValue(function (TemplateInterface $driver, $cell, $value) {
// Hook will be called for every cell's value which is changing
(new \AnourValar\Office\SheetsService())
->hookValue(function (SheetsInterface $driver, $cell, $value, int $sheetIndex) {
// Hook will be called for every cell which is changing

$value .= ' world';
return $value;
})
->generate(
'template3.ods',
'template3.ods', // ods template
$data,
\AnourValar\Office\Format::Ods // template's format
true // cells auto format instead of template setup
)
->saveAs('generated_document.xlsx');

// Available hooks:
// hookLoad: Closure(TemplateInterface $driver, string $templateFile, Format $templateFormat)
// hookBefore: Closure(TemplateInterface $driver, array &$data)
// hookValue: Closure(TemplateInterface $driver, string $cell, mixed $value)
// hookAfter: Closure(TemplateInterface $driver)
// hookLoad: Closure(SheetsInterface $driver, string $templateFile, Format $templateFormat)
// hookBefore: Closure(SheetsInterface $driver, array &$data)
// hookValue: Closure(SheetsInterface $driver, string $cell, mixed $value, int $sheetIndex)
// hookAfter: Closure(SheetsInterface $driver)
```

**generated_document.xlsx:**
Expand All @@ -186,11 +186,11 @@ $data = [
],
];

(new \AnourValar\Office\TemplateService())
(new \AnourValar\Office\SheetsService())
->hookLoad(function ($driver, string $templateFile, $templateFormat)
{
// create empty document instead of using existing
$driver->create();
return $driver->create();
})
->hookBefore(function ($driver, array &$data)
{
Expand All @@ -212,7 +212,7 @@ $data = [
}
})
->generate('', $data)
->saveAs('generated_document.xlsx'));
->saveAs('generated_document.xlsx');
```

**Dynamic template overview**
Expand All @@ -229,10 +229,10 @@ $data = [
$dataA = ['foo' => 'hello'];
$dataB = ['foo' => 'world'];

$documentA = (new \AnourValar\Office\TemplateService())->generate('template.xlsx', $dataA);
$documentB = (new \AnourValar\Office\TemplateService())->generate('template.xlsx', $dataB);
$documentA = (new \AnourValar\Office\SheetsService())->generate('template.xlsx', $dataA);
$documentB = (new \AnourValar\Office\SheetsService())->generate('template.xlsx', $dataB);

$mixer = new \AnourValar\Office\MixerService();
$mixer = new \AnourValar\Office\Mixer();
$mixer($documentA, $documentB)->saveAs('generated_document.xlsx');
```

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "anourvalar/office",
"description": "Document generation from existing Excel templates | Export tables to Excel (Grids)",
"keywords": [
"excel", "xls", "xlsx", "template", "view", "document", "contract", "report", "generate", "engine",
"markers", "replacers", "templator", "templater", "pdf", "ods", "grid", "export", "generator", "anourvalar"
"excel", "xls", "xlsx", "template", "view", "document", "contract", "report", "generate", "engine", "fill",
"markers", "replacers", "templator", "templater", "pdf", "ods", "grid", "export", "generator", "anourvalar",
"variables"
],
"homepage": "https://github.com/AnourValar/office",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/MixInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AnourValar\Office\Drivers;

interface MixInterface
interface MixInterface extends MultiSheetInterface
{
/**
* Set title for an active sheet
Expand Down
21 changes: 21 additions & 0 deletions src/Drivers/MultiSheetInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace AnourValar\Office\Drivers;

interface MultiSheetInterface
{
/**
* Set active sheet
*
* @param int $index
* @return self
*/
public function setSheet(int $index): self;

/**
* Get sheets count
*
* @return int
*/
public function getSheetCount(): int;
}
Loading

0 comments on commit 4fc9973

Please sign in to comment.