Coder Social home page Coder Social logo

webappbuilder / fast-excel-templator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from avadim483/fast-excel-templator

0.0 0.0 0.0 235 KB

Lightweight and very fast Excel Spreadsheet generator from XLSX-templates in PHP

License: MIT License

PHP 100.00%

fast-excel-templator's Introduction

FastExcelTemplator

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

  • Supports XLSX format only (Office 2007+) with multiple worksheets
  • Transfers from templates to target spreadsheets styles, images, notes
  • Replaces the entire cell values and substrings
  • You can use any row from a template as row template to insert and replace a row with new values
  • The library can read styling options of cells - formatting patterns, colors, borders, fonts, etc.

Installation

Use composer to install FastExcelTemplator into your project:

composer require avadim/fast-excel-templator

Usage

Example of template

demo1-tpl.png

From this template you can get a file like this

demo1-out.png

// Open template and set output file
$excel = Excel::template($tpl, $out);
// Get the first sheet
$sheet = $excel->sheet();

$fillData = [
    '{{COMPANY}}' => 'Comp Stock Shop',
    '{{ADDRESS}}' => '123 ABC Street',
    '{{CITY}}' => 'Peace City, TN',
];

// Replaces entire cell values for the sheet
// If the value is '{{COMPANY}}', then this value will be replaced,
// but if the value 'Company Name {{COMPANY}}', then this value will not be replaced 
$sheet->fill($fillData);

// Replaces any occurring substrings
// If the value is '{{DATE}}' or 'Date: {{DATE}}', then substring '{{DATE}}' will be replaced,
$replaceData = ['{{BULK_QTY}}' => 12, '{{DATE}}' => date('m/d/Y')];
$sheet->replace($fillData);

Also, you can use any row as a template

// Get the specified row (number 6) as a template
$rowTemplate = $sheet->getRowTemplate(6);
// You can insert template row many times with new data
$rowData = [
    // Value for the column A
    'A' => 'AA-8465-947563',
    // Value for the column B
    'B' => 'NEC Mate Type ML PC-MK29MLZD1FWG',
    // And so on...
    'C' => 816,
    'D' => 683,
];
// Replace row 6 instead of a template row
$sheet->replaceRow(6, $rowTemplate, $rowData);

// New data for the new row
$rowData = [
    // ...
];
// Add new row from the same template after the last insertion
$sheet->insertRowAfterLast($rowTemplate, $rowData);

// ...
// Save new file
$excel->save();

You can find code examples in /demo folder

List of functions

Class Excel

Excel::template($template, $output);

  • fill(array $replacement) - Replaces the entire cell value for all sheets
  • replace(array $replacement) - Replaces a substring in a cell for all sheets
  • save()

Class Sheet

  • fill(array $replacement) - Replaces the entire cell value for the sheet
  • replace(array $replacement) - Replaces a substring in a cell for the sheet
  • getRowTemplate($rowNumber) - Gets template from the row
  • insertRow($rowNumber, $rowTemplate, ?array $cellData = [])
  • replaceRow($rowNumber, $rowTemplate, ?array $cellData = [])
  • insertRowAfterLast($rowTemplate, ?array $cellData = [])

Do you like FastExcelTemplator?

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

  • USDT (TRC20) TSsUFvJehQBJCKeYgNNR1cpswY6JZnbZK7
  • USDT (ERC20) 0x5244519D65035aF868a010C2f68a086F473FC82b
  • ETH 0x5244519D65035aF868a010C2f68a086F473FC82b

Or just give me a star on GitHub :)

fast-excel-templator's People

Contributors

avadim483 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.