Download the PHP package avadim/fast-excel-templator without Composer

On this page you can find all versions of the php package avadim/fast-excel-templator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package fast-excel-templator

FastExcelTemplator

πŸ‡¬πŸ‡§ English Β· πŸ‡·πŸ‡Ί Русский

FastExcelTemplator is a part of the FastExcelPhp Project which consists of

Introduction

FastExcelTemplator can generate Excel-compatible spreadsheets in XLSX format (Office 2007+) from XLSX templates, very quickly and with minimal memory usage. This library is designed to be lightweight, super-fast and requires minimal memory usage.

Features

Which library do I need?

"Working with Excel in PHP" is really three different tasks, each with its own tool in the FastExcelPhp family:

Your task Use
Read data from an existing file FastExcelReader
Build a spreadsheet from scratch in code FastExcelWriter
Fill a ready-made XLSX form with data FastExcelTemplator (this library)

Reach for FastExcelTemplator when you already have a designed XLSX document (an invoice, act, contract, report) and only need to put data into it β€” keeping the logo, borders, number formats and formulas that are already in the file. If you catch yourself re-creating in code the formatting that already exists in a file, you want the template approach.

Installation

Use composer to install FastExcelTemplator into your project:

Requirements

How it works

Understanding the design explains both what the library does effortlessly and where its limits are.

Templates Usage

Example of template

From this template you can get a file like this

Step 1 - open template and set replacements

fill() vs replace() β€” the most common gotcha:

Both maps apply to every cell the library writes to the output β€” transferred rows and inserted rows alike. Step 2 - transfer the top of the sheet and the table headers from the template to the output file

There are 6 rows read from template, the output file also contains 6 lines

Step 3 - insert inner table rows

We filled in and inserted rows 7, 8 and 9

Step 4 - Now transfer the remaining rows and save file

You can find code examples in /demo folder

Modification of Spreadsheets

Use the method to read rows, modify them using callback, and write them to the output file.

You can add one or more cells to the end of a row in the callback function. The styles and value from the source cell will be copied to the new cell. If you do not explicitly specify a source cell, the last cell in the row will be used as the source.

Also, you can clone any cell (with styles and value) to other cell

If you need to remove cells, use the .

removeCell() and removeCells() affect the current row, not the workbook's column structure. Values, styles and horizontal merges move together; an interior removal shrinks a horizontal merge. Removals affecting multi-row merges throw an exception. See the reference semantics.

Use $rowData->setValue('B', null) to clear content and the previous formula while retaining formatting. Zero, false and the empty string remain distinct valid values. Strings starting with = are written as formulas.

Repeating rows and alternating styles

getRowTemplate($n) grabs a single row as a reusable template. To repeat a block of several rows β€” or to alternate row styles ("zebra") β€” capture a range with getRowTemplates($min, $max):

Both methods return a RowTemplateCollection; insertRow() takes the next template from it on each call and wraps around at the end.

Each insertion uses a copy of its template. Columns omitted from $cellData retain the template's values and formulas; they do not inherit values from the previous insertion. The template is unchanged. The insertion cycle is independent of foreach over the collection. Missing rows within a valid template range become empty templates.

Capturing templates advances the main read cursor to the requested range end by default. Pass true as the last argument β€” getRowTemplate(7, true) or getRowTemplates(7, 8, true) β€” to retain its position. Ranges must be positive and ordered; when dimension is present, its bounds are checked. An empty collection cannot be inserted.

nextTemplate() selects from the same cycle used by insertRow(), independently of foreach, next() and rewind(). Adding or deleting a template restarts the insertion cycle. Public next() retains its legacy cyclic behavior.

Transferring and skipping rows

Method Source positions processed Result
transferRows($count) Next $count positions Copy rows to output
skipRows($count) Next $count positions Advance without writing
transferRowsUntil($row) Through source row $row, inclusive Copy rows to output
skipRowsUntil($row) Through source row $row, inclusive Advance without writing

null processes to EOF, 0 does nothing, and negative values throw an exception. Empty positions in sparse sheets count toward the limit. Until methods do not consume a later existing row beyond the boundary. Repeated EOF operations do not add rows.

Transfer callbacks receive the source row number, target row number and RowTemplate. Return the row to write it, null to omit it, or false to stop. A stopped row has already been read but is not written; a subsequent call resumes with the following row.

Working with multiple sheets

A template may contain several worksheets. Address a sheet by name with sheet($name), or iterate over all of them with sheets():

Sheets can be processed in any order. Generated data is mapped to each sheet's original XML part even when workbook order differs from sheetN.xml numbering.

Saving the result

Call save() explicitly. The workbook is generated in a temporary file in the destination directory before the completed file replaces the output. Generation or publication failures preserve the previous output. The destination directory must exist and allow file creation.

save($path, false) refuses to overwrite even a file created during generation. This mode uses a hard link and requires filesystem support for it. Saving to the source template path is rejected: choose a separate output file. Destroying the object does not automatically save the workbook.

Checking metadata preservation

Default mode saves with the limitations in the XLSX support matrix and records diagnostics. For example, validation and conditional-formatting ranges retain their template coordinates when rows are inserted.

Strict-mode diagnostics remain available after catching the exception; saving stops at the first detected limitation and preserves the existing destination. See the diagnostic codes and exception example.

Sending the file to the browser

Besides save(), you can stream the generated file straight to the client with the correct HTTP headers:

download() sends one file per response, so to hand over many documents at once, save them and pack them into an archive yourself.

Limitations

See the XLSX support matrix for metadata preservation, reference semantics and structural limitations. Pass ['strict_metadata' => true] as the third argument of Excel::template() to reject unsupported transformations. metadataDiagnostics() returns diagnostics from the latest save attempt. setValue('A', null) clears cell content and its formula while retaining formatting.

FastExcelTemplator is built for one job β€” filling XLSX templates β€” and deliberately does not do everything:

FAQ

My placeholder was not replaced. Check fill() vs replace(). fill() only replaces a cell whose value equals the key exactly; if the marker sits inside other text (e.g. Date: {{DATE}}), use replace(), which matches substrings.

A formula shows up as text, or the cell is empty until I open the file. The library writes formulas but does not evaluate them β€” Excel computes the result when the file is opened. Make sure the value is a real formula starting with =.

How do I keep the logo / images / notes from the template? Ordinary fill()/replace() and row transfer retain original images, notes and relationships. After structural changes, their anchors retain template coordinates; diagnostics report this limitation and strict mode rejects it.

I get Allowed memory size exhausted on a large file. The library streams, so the bottleneck is usually your data source. Pull rows from the database with a cursor/generator instead of loading them all into an array (fetchAll()) before the insert loop.

Can I use an old .xls file as a template? No. Only XLSX (Office 2007+) is supported. Convert the .xls to .xlsx first (e.g. in Excel or LibreOffice) and use the result as the template.

List of Functions

Changes in Unreleased.

Do you like FastExcelTemplator?

if you find this package useful you can support and donate to me for a cup of coffee:

Or just give me a star on GitHub :)


All versions of fast-excel-templator with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-zip Version *
ext-json Version *
ext-mbstring Version *
ext-xmlreader Version *
ext-dom Version *
avadim/fast-excel-writer Version ^6.16.1
avadim/fast-excel-reader Version ^4.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package avadim/fast-excel-templator contains the following files

Loading the files please wait ...