Convert Figma logo to code with AI

viest logophp-ext-xlsxwriter

🚀 PHP Extension for creating and reader XLSX files.

2,294
235
2,294
68

Top Related Projects

Lightweight XLSX Excel Spreadsheet Writer in PHP

A pure PHP library for reading and writing spreadsheet files

4,236

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

A Python module for creating Excel XLSX files.

Parse and retrieve data from Excel XLSx files

11,443

ARCHIVED

Quick Overview

php-ext-xlsxwriter is a PHP extension for creating Excel XLSX files. It provides a fast and memory-efficient way to generate large Excel spreadsheets directly from PHP, without requiring additional libraries or dependencies.

Pros

  • High performance and low memory usage compared to pure PHP solutions
  • Native PHP extension, providing better integration with PHP applications
  • Supports various Excel features like formulas, cell formatting, and merged cells
  • 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 XLSX format, not supporting older Excel formats or other spreadsheet types
  • May have compatibility issues with certain PHP versions or environments
  • Less flexible than some pure PHP libraries for advanced Excel manipulations

Code Examples

  1. Creating a simple spreadsheet:
$config = ['path' => '/path/to/file.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName('tutorial01.xlsx', 'sheet1')
    ->header(['Item', 'Cost'])
    ->data([
        ['Rent', 1000],
        ['Gas',  100],
        ['Food', 300],
        ['Gym',  50],
    ])
    ->output();
  1. Adding formulas:
$config = ['path' => '/path/to/file.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName('tutorial02.xlsx', 'sheet1')
    ->header(['Item', 'Cost'])
    ->data([
        ['Rent', 1000],
        ['Gas',  100],
        ['Food', 300],
        ['Gym',  50],
    ])
    ->setColumn('A:A', 15)
    ->setColumn('B:B', 10)
    ->insertText(4, 0, 'Total')
    ->insertFormula(4, 1, '=SUM(B1:B4)')
    ->output();
  1. Applying cell formatting:
$config = ['path' => '/path/to/file.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$format = new \Vtiful\Kernel\Format($excel);
$boldFormat = $format->bold()->toResource();
$currencyFormat = $format->numeric('$#,##0.00')->toResource();

$filePath = $excel->fileName('tutorial03.xlsx', 'sheet1')
    ->header(['Item', 'Cost'])
    ->data([
        ['Rent', 1000],
        ['Gas',  100],
        ['Food', 300],
        ['Gym',  50],
    ])
    ->setColumn('A:A', 15, $boldFormat)
    ->setColumn('B:B', 12, $currencyFormat)
    ->output();

Getting Started

  1. Install the extension:

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

    extension=xlswriter.so
    
  3. Verify the installation:

    if (extension_loaded('xlswriter')) {
        echo "xlswriter extension is installed!";
    } else {
        echo "xlswriter extension is not installed.";
    }
    
  4. Start using the extension in your PHP code as shown in the examples above.

Competitor Comparisons

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
  • More flexible for customization and integration into existing PHP projects

Cons of PHP_XLSXWriter

  • Generally slower performance compared to the C extension
  • May consume more memory for large datasets
  • Limited support for advanced Excel features

Code Comparison

PHP_XLSXWriter:

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

php-ext-xlsxwriter:

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

Both libraries offer straightforward APIs for creating Excel files, but PHP_XLSXWriter uses a more traditional object-oriented approach, while php-ext-xlsxwriter employs a fluent interface. The C extension (php-ext-xlsxwriter) is likely to provide better performance for large datasets or frequent file generation, while PHP_XLSXWriter offers greater flexibility and easier integration into pure PHP environments.

A pure PHP library for reading and writing spreadsheet files

Pros of PhpSpreadsheet

  • More feature-rich, supporting a wide range of spreadsheet operations
  • Pure PHP implementation, easier to install and use without system dependencies
  • Supports reading and writing multiple file formats (XLSX, XLS, CSV, ODS)

Cons of PhpSpreadsheet

  • Slower performance, especially for large datasets
  • Higher memory usage due to its pure PHP implementation
  • Steeper learning curve due to more complex API

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-xlsxwriter:

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

PhpSpreadsheet offers a more intuitive API for cell manipulation, while php-ext-xlsxwriter focuses on simplicity and performance for basic spreadsheet creation. The php-ext-xlsxwriter example demonstrates its streamlined approach to creating a file with headers and data in fewer lines of code.

4,236

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

Pros of Spout

  • Pure PHP implementation, no need for extensions or additional libraries
  • Supports reading and writing multiple formats (XLSX, CSV, ODS)
  • Memory-efficient streaming for large files

Cons of Spout

  • Generally slower performance compared to native extensions
  • Limited formatting options for created spreadsheets
  • Lacks some advanced features available in php-ext-xlsxwriter

Code Comparison

php-ext-xlsxwriter:

$config = ['path' => '/path/to/file.xlsx'];
$excel  = new \Vtiful\Kernel\Excel($config);

$filePath = $excel->fileName('tutorial01.xlsx')
    ->header(['Item', 'Cost'])
    ->data([['Rent', 1000], ['Gas', 100]])
    ->output();

Spout:

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

$writer->addRow(['Item', 'Cost']);
$writer->addRows([['Rent', 1000], ['Gas', 100]]);

$writer->close();

Both libraries offer straightforward APIs for creating Excel files. php-ext-xlsxwriter uses a fluent interface, while Spout employs a more traditional method-calling approach. The php-ext-xlsxwriter example showcases its ability to define headers and data in a single chain, whereas Spout separates these operations into distinct method calls.

A Python module for creating Excel XLSX files.

Pros of XlsxWriter

  • Written in Python, offering better integration with Python-based projects
  • More comprehensive documentation and examples
  • Supports a wider range of Excel features and formatting options

Cons of XlsxWriter

  • Slower performance compared to php-ext-xlsxwriter
  • Requires Python installation and setup, which may not be ideal for PHP-centric environments

Code Comparison

XlsxWriter:

import xlsxwriter

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

php-ext-xlsxwriter:

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

$excel->fileName('tutorial01.xlsx', 'sheet1')
    ->header(['Item', 'Cost'])
    ->output();

Both libraries offer straightforward ways to create Excel files, but XlsxWriter provides more flexibility in terms of formatting and cell manipulation. php-ext-xlsxwriter, being a PHP extension, is likely to offer better performance for PHP applications.

The choice between these libraries depends on the specific project requirements, programming language preference, and performance needs. XlsxWriter is more suitable for Python-based projects or when advanced Excel features are required, while php-ext-xlsxwriter is better for PHP environments where speed is a priority.

Parse and retrieve data from Excel XLSx files

Pros of simplexlsx

  • Pure PHP implementation, no extensions required
  • Easy to use and integrate into existing PHP projects
  • Supports reading and writing Excel files

Cons of simplexlsx

  • Slower performance compared to native extensions
  • Limited formatting options for writing Excel files
  • May consume more memory for large files

Code Comparison

simplexlsx:

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

php-ext-xlsxwriter:

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

simplexlsx offers a straightforward approach to reading Excel files, while php-ext-xlsxwriter provides a more efficient method for writing Excel files with better performance. The choice between the two depends on specific project requirements, such as the need for native extension support, performance considerations, and the complexity of Excel operations required.

11,443

ARCHIVED

Pros of PHPExcel

  • More feature-rich, supporting a wide range of Excel functionalities
  • Better documentation and community support
  • Cross-platform compatibility (works on various PHP environments)

Cons of PHPExcel

  • Slower performance, especially for large datasets
  • Higher memory consumption
  • Requires more setup and configuration

Code Comparison

PHPExcel:

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

php-ext-xlsxwriter:

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

php-ext-xlsxwriter is a PHP extension that offers faster performance and lower memory usage compared to PHPExcel. It's particularly efficient for generating large Excel files. However, it has fewer features and may require additional setup as it's an extension rather than a pure PHP library. The code for php-ext-xlsxwriter is generally more concise, as shown in the comparison above.

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