Skip to content
Advertisement

Exporting data to excel (multiple sheets) using php

I am trying to export data to Excel using this PHP Class, so far things are working fine and the export is being generated. But now I have a new requirement of generating multiple sheets inside a single excel file.

For example if i have two arrays, i want both to be on separate sheets.

$myarray1 =  array (
       1 => array ("Oliver", "Peter", "Paul"),
            array ("Marlene", "Mica", "Lina")
    );

$myarray2 =  array (
       1 => array ("Oliver", "Peter", "Paul"),
            array ("Marlene", "Mica", "Lina")
    );

At present both arrays are being exported on a single sheet

$xls = new Excel_XML;
$xls->addArray ( $myarray );
$xls->addArray ( $myarray2 );
$xls->generateXML ( "testfile" );

I am wondering if someone tried this before and was able to achieve it and I will appreciate any help I can get on this.

Advertisement

Answer

i would suggest you to use PHPExcel library.supports variety of formats, can do visual formatting and is easy to use. You can find more about it at their webpage: http://phpexcel.codeplex.com/

You can do a lot more of course, reading excel files, setting visual styles, creating plots, expressions and lot more.

you can even use fgetcsv http://php.net/manual/en/function.fgetcsv.php

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement