Convert Figma logo to code with AI

viest logophp-ext-xlswriter

🚀 PHP Extension for creating and reader XLSX files.

2,247
232
2,247
54

Top Related Projects

A pure PHP library for reading and writing spreadsheet files

11,464

ARCHIVED

Lightweight XLSX Excel Spreadsheet Writer in PHP

A Python module for creating Excel XLSX files.

4,220

Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

Parse and retrieve data from Excel XLSx files

Quick Overview

PHP-ext-xlswriter is a PHP extension for creating Excel XLSX files. It's designed to be fast and memory-efficient, making it suitable for generating large spreadsheets. The extension is built on top of the libxlsxwriter library, providing a native PHP interface for Excel file creation.

Pros

  • High performance and low memory usage compared to other PHP Excel libraries
  • Supports a wide range of Excel features, including formulas, charts, and cell formatting
  • Easy to install and use as a PHP extension
  • Actively maintained with regular updates and bug fixes

Cons

  • Requires compilation and installation as a PHP extension, which may be challenging for some users
  • Limited to writing XLSX files; cannot read or modify existing Excel files
  • May have compatibility issues with some PHP environments or hosting providers
  • Learning curve for users unfamiliar with PHP extensions

Code Examples

Creating a simple Excel file:

<?php
$config = ['path' => './example.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')
    ->header(['Name', 'Age'])
    ->data([
        ['John Doe', 30],
        ['Jane Doe', 25]
    ])
    ->output();

Adding formulas to cells:

<?php
$config = ['path' => './example.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName('tutorial02.xlsx', 'sheet1')
    ->header(['Item', 'Cost', 'Qty', 'Total'])
    ->data([
        ['Apple', 0.5, 10],
        ['Orange', 0.6, 15],
        ['Banana', 0.4, 20]
    ])
    ->setColumn('D:D', 15, \Vtiful\Kernel\Format::FORMAT_CURRENCY_USD)
    ->setCell('D2', '=B2*C2')
    ->setCell('D3', '=B3*C3')
    ->setCell('D4', '=B4*C4')
    ->setCell('D5', '=SUM(D2:D4)')
    ->output();

Creating a chart:

<?php
$config = ['path' => './example.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName('tutorial03.xlsx', 'sheet1')
    ->header(['Year', 'Sales'])
    ->data([
        [2018, 100],
        [2019, 120],
        [2020, 140],
        [2021, 180]
    ])
    ->insertChart(0, 4, [
        'type'   => 'column',
        'series' => [
            ['name' => 'Sales', 'categories' => '=sheet1!$A$2:$A$5', 'values' => '=sheet1!$B$2:$B$5']
        ],
        'title'  => ['name' => 'Sales by Year']
    ])
    ->output();

Getting Started

  1. Install the extension:

    pecl install xlswriter
    
  2. Add the extension to your php.ini file:

    extension=xlswriter.so
    
  3. Create a new PHP file and start using the extension:

    <?php
    $config = ['path' => './'];
    $excel  = new \Vtiful\Kernel\Excel($config);
    
    $excel->fileName('example.xlsx')
        ->writeSheetHeader('Sheet1', ['Name', 'Age'])
        ->writeSheetRow('Sheet1', ['John Doe', 30])
        ->writeSheetRow('Sheet1', ['Jane Doe', 25])
        ->output();
    

Competitor Comparisons

A pure PHP library for reading and writing spreadsheet files

Pros of PhpSpreadsheet

  • More feature-rich, supporting a wider range of spreadsheet operations
  • Pure PHP implementation, making it easier to install and use across different environments
  • Actively maintained with regular updates and a large community

Cons of PhpSpreadsheet

  • Slower performance, especially when dealing with large datasets
  • Higher memory consumption due to its PHP-based implementation
  • Steeper learning curve due to its extensive API and features

Code Comparison

PhpSpreadsheet:

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World!');
$writer = new Xlsx($spreadsheet);
$writer->save('hello_world.xlsx');

php-ext-xlswriter:

$config = ['path' => './'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('tutorial.xlsx')
    ->header(['name', 'age'])
    ->output();

PhpSpreadsheet offers a more intuitive API for complex operations, while php-ext-xlswriter provides a simpler interface for basic tasks. The latter's C extension-based implementation results in significantly better performance, especially for large datasets or when generating multiple files.

11,464

ARCHIVED

Pros of PHPExcel

  • Pure PHP implementation, making it easier to install and use without additional system dependencies
  • More comprehensive feature set, including advanced formatting options and chart creation
  • Wider compatibility with various Excel file formats, including older versions

Cons of PHPExcel

  • Slower performance, especially when dealing with large datasets
  • Higher memory consumption, which can be problematic for large files
  • Less actively maintained, with the last major release in 2015

Code Comparison

PHPExcel:

$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello World');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('myfile.xlsx');

php-ext-xlswriter:

$config = ['path' => './'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('tutorial.xlsx')
    ->header(['name', 'age'])
    ->output();

php-ext-xlswriter is a PHP extension that offers significantly better performance and lower memory usage compared to PHPExcel. It's particularly well-suited for handling large datasets and high-volume Excel file generation. However, it requires compilation and installation as a PHP extension, which may be more challenging in some environments. php-ext-xlswriter also has a more limited feature set compared to PHPExcel, focusing primarily on efficient data writing and basic formatting.

Lightweight XLSX Excel Spreadsheet Writer in PHP

Pros of PHP_XLSXWriter

  • Pure PHP implementation, no external dependencies required
  • Easy to install and use in any PHP environment
  • Supports older PHP versions (5.2+)

Cons of PHP_XLSXWriter

  • Generally slower performance compared to php-ext-xlswriter
  • Limited advanced Excel features and formatting options
  • May consume more memory for large datasets

Code Comparison

PHP_XLSXWriter:

$writer = new XLSXWriter();
$writer->writeSheetHeader('Sheet1', array('Col1' => 'string', 'Col2' => 'string'));
$writer->writeSheetRow('Sheet1', array('A1', 'B1'));
$writer->writeToFile('example.xlsx');

php-ext-xlswriter:

$excel = new \Vtiful\Kernel\Excel(['path' => './']);
$filePath = $excel->fileName('tutorial.xlsx')
    ->header(['Name', 'Age'])
    ->data([['viest', 21]])
    ->output();

Both libraries offer straightforward APIs for creating Excel files, but php-ext-xlswriter provides a more concise syntax and potentially better performance due to its C implementation.

A Python module for creating Excel XLSX files.

Pros of XlsxWriter

  • Cross-platform compatibility: Works on various operating systems
  • Rich feature set: Supports a wide range of Excel functionalities
  • Pure Python implementation: Easy to install and use without external dependencies

Cons of XlsxWriter

  • Performance: May be slower for large datasets compared to C extensions
  • Memory usage: Can consume more memory for complex spreadsheets
  • Limited real-time writing: Primarily designed for writing entire workbooks at once

Code Comparison

XlsxWriter:

import xlsxwriter

workbook = xlsxwriter.Workbook('example.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello, World!')
workbook.close()

php-ext-xlswriter:

$config = ['path' => './example.xlsx'];
$excel = new \Vtiful\Kernel\Excel($config);
$excel->fileName('example')
    ->header(['Hello', 'World'])
    ->output();

Both libraries offer straightforward APIs for creating Excel files, but php-ext-xlswriter is specifically designed for PHP and leverages C extensions for improved performance. XlsxWriter, being a Python library, provides a more Pythonic approach and may be easier to integrate into existing Python projects.

4,220

Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

Pros of Spout

  • Pure PHP library, no extensions required
  • Supports reading and writing multiple formats (XLSX, CSV, ODS)
  • Memory-efficient streaming for large files

Cons of Spout

  • Slower performance compared to native extensions
  • Limited formatting options for Excel files
  • Lacks advanced Excel features like formulas and charts

Code Comparison

Spout:

$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($filePath);
$writer->addRow($rowData);
$writer->close();

php-ext-xlswriter:

$excel = new \Vtiful\Kernel\Excel(['path' => './']);
$filePath = $excel->fileName('file.xlsx')
    ->header($header)
    ->data($data)
    ->output();

Both libraries offer straightforward APIs for creating Excel files, but php-ext-xlswriter provides a more compact syntax. Spout's approach is more verbose but offers greater flexibility in terms of supported file formats.

php-ext-xlswriter, being a native extension, generally offers better performance for large datasets and complex operations. However, Spout's pure PHP implementation makes it more portable and easier to deploy in various environments.

Spout excels in memory efficiency and handling large files through streaming, while php-ext-xlswriter leverages C extensions for speed and advanced Excel features. The choice between the two depends on specific project requirements, performance needs, and deployment constraints.

Parse and retrieve data from Excel XLSx files

Pros of simplexlsx

  • Pure PHP implementation, no extensions required
  • Easy to install and use, especially in shared hosting environments
  • Supports reading both XLSX and XLS formats

Cons of simplexlsx

  • Generally slower performance compared to php-ext-xlswriter
  • Limited writing capabilities, primarily focused on reading Excel files
  • May consume more memory for large files

Code Comparison

simplexlsx (reading):

$xlsx = SimpleXLSX::parse('file.xlsx');
foreach ($xlsx->rows() as $row) {
    print_r($row);
}

php-ext-xlswriter (writing):

$config = ['path' => './'];
$excel = new \Vtiful\Kernel\Excel($config);
$filePath = $excel->fileName('file.xlsx')
    ->header(['name', 'age'])
    ->data([['John', 28], ['Jane', 25]])
    ->output();

Both libraries serve different primary purposes: simplexlsx focuses on reading Excel files, while php-ext-xlswriter excels at writing Excel files. simplexlsx is more accessible and easier to set up, especially in environments where installing extensions is challenging. However, php-ext-xlswriter offers better performance and more advanced writing capabilities, making it suitable for generating complex Excel files or handling large datasets.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

php-ext-xlswriter
php-ext-xlswriter
php-ext-xlswriter
php-ext-xlswriter php-ext-xlswriter php-ext-xlswriter php-ext-xlswriter
php-ext-xlswriter php-ext-xlswriter php-ext-xlswriter php-ext-xlswriter php-ext-xlswriter php-ext-xlswriter

Why use xlswriter

Please refer to the image below. PHPExcel has been unable to work properly for memory reasons at 40,000 and 100000 points, but it can be resolved by modifying the ini configuration, but the time may take longer to complete the work;

php-excel

xlswriter is a PHP C Extension that can be used to write text, numbers, formulas and hyperlinks to multiple worksheets in an Excel 2007+ XLSX file. It supports features such as:

Writer
  • 100% compatible Excel XLSX files.
  • Full Excel formatting.
  • Merged cells.
  • Defined names.
  • Autofilters.
  • Charts.
  • Data validation and drop down lists.
  • Worksheet PNG/JPEG images.
  • Memory optimization mode for writing large files.
  • Works on Linux, FreeBSD, OpenBSD, OS X, Windows.
  • Compiles for 32 and 64 bit.
  • FreeBSD License.
  • The only dependency is on zlib.
Reader
  • Full read data
  • Cursor read data
  • Read by data type

Install

Unix
pecl install xlswriter
Windows

download dll

Benchmark

Test environment: Macbook Pro 13 inch, Intel Core i5, 16GB 2133MHz LPDDR3 Memory, 128GB SSD Storage.

Export

Two memory modes export 1 million rows of data (27 columns, data is string)

  • Normal mode: only 29S is needed, and the memory only needs 2083MB;
  • Fixed memory mode: only need 52S, memory only needs <1MB;
Import

1 million rows of data (1 columns, data is inter)

  • Full mode: Just 3S, the memory is only 558MB;
  • Cursor mode: Just 2.8S, memory is only <1MB;

Documents

Includes extensive and detailed instructions that make it easy to get started with xlswriter.

PECL Repository

pecl

IDE Helper

composer require viest/php-ext-xlswriter-ide-helper:dev-master

Exchange group

php-ext-xlswriter

Financial donation

php-ext-xlswriter

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

BSD License

FOSSA Status

Stargazers over time

Stargazers over time