A PHP +8.1 library called AnourValar/office is used to create documents using XLSX templates. Using a template similar to the one below as an example (found in the readme):
![](https://eziblogs.com/wp-content/uploads/2023/11/image-194-1024x296.png)
You can create a document with the template values by using the code below:
$data = [
// scalar
'vat' => 'No',
'total' => [
'price' => 2004.14,
'qty' => 3,
],
// one-dimensional table
'products' => [
[
'name' => 'Product #1',
'price' => 989,
'qty' => 1,
'date' => new \DateTime('2022-03-30'),
],
[
'name' => 'Product #2',
'price' => 1015.14,
'qty' => 2,
'date' => new \DateTime('2022-03-31'),
],
],
];
// Save as XLSX (Excel)
(new \AnourValar\Office\TemplateService())
->generate(
'template1.xlsx', // path to template
$data // input data
)
->saveAs(
'generated_document.xlsx', // path to save
\AnourValar\Office\Format::Xlsx // save format
);
Which, using the template1.xlsx file as a basis, generates the following:
![](https://eziblogs.com/wp-content/uploads/2023/11/image-195-1024x271.png)
This package supports a variety of save formats for the document, such as:
- XLSX
- HTML
- ODS
This package does not only generate files from XLSX templates; it also supports:
- Two-dimensional tables
- Image insertion
- Dynamic templates
- Merge multiple documents into a single file
- Export Table (grid service)