Coder Social home page Coder Social logo

php_xlsxwriter's Introduction

PHP_XLSXWriter

This library is designed to be lightweight, and have relatively low memory usage.

It is designed to output an Excel spreadsheet in with (Office 2007+) xlsx format, with just basic features supported:

  • supports PHP 5.2+
  • assumes input is valid UTF-8
  • multiple worksheets
  • supports a few simple cell formats:
    • simple $0.00 currency format
    • simple Y-M-D/Y-M-D H:m:s format

Give this library a try, if you find yourself running out of memory writing spreadsheets with PHPExcel.

Simple example:

$data = array(
    array('year','month','amount'),
    array('2003','1','220'),
    array('2003','2','153.5'),
);

$writer = new XLSXWriter();
$writer->writeSheet($data);
$writer->writeToFile('output.xlsx');

Multiple Sheets:

$data1 = array(  
     array('5','3'),
     array('1','6'),
);
$data2 = array(  
     array('2','7','9'),
     array('4','8','0'),
);

$writer = new XLSXWriter();
$writer->setAuthor('Doc Author');
$writer->writeSheet($data1);
$writer->writeSheet($data2);
echo $writer->writeToString();

Cell Formatting:

$header = array(
  'create_date'=>'date',
  'quantity'=>'string',
  'product_id'=>'string',
  'amount'=>'money',
  'description'=>'string',
);
$data = array(
    array('2013-01-01',1,27,'44.00','twig'),
    array('2013-01-05',1,'=C1','-44.00','refund'),
);

$writer = new XLSXWriter();
$writer->writeSheet($data,'Sheet1', $header);
$writer->writeToFile('example.xlsx');

Load test with 50000 rows: (runs fast, with low memory usage)

include_once("xlsxwriter.class.php");

$data = array();
for($i=0; $i<50000; $i++)
{
   $data[] = array(rand()%10000,rand()%10000,rand()%10000,rand()%10000);
}
echo '#'.floor((memory_get_peak_usage())/1024/1024)."MB"."\n";

$writer = new XLSXWriter();
$writer->writeSheet($data);
$writer->writeToFile('output.xlsx');
echo '#'.floor((memory_get_peak_usage())/1024/1024)."MB"."\n";

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.