Export steps
1. Create a new Excel table
Instantiate the Phpexcel class
2. Create sheet (built-in table)
Createsheet ()
Setactivesheetindex ()
Getactivesheet ()
3. Populating the data
Setcellvalue ()
4. Save the file
Phpexcel_iofactory::createwriter ()
Save ()
<?php$dir = DirName (__file__);//include classrequire_once ($dir. '/phpexcel.php '); $objPHPExcel = new Phpexcel (); Instantiate the Phpexcel class $objphpexcel->setactivesheetindex (0); $objSheet = $objPHPExcel->getactivesheet (); Get Current Sheet$objsheet->settitle ("demo"); Set the name of the current sheet $array = Array ("name", "Score"), Array ("John Doe", "" "), Array (" Harry ","->setcellvalue "), $objSheet A5 , "name"), $objSheet->setcellvalue ("B5", "score"); Fill the current sheet with data $objsheet->setcellvalue ("A6", "Zhang San"), $objSheet->setcellvalue ("B6", "n"); $objSheet FromArray ($array); Load data block directly fill data $objwriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel2007 '); Generates an Excel file in the specified format $objwriter->save (str_replace ('. php ', '. xls ', __file__));
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Export files using Phpexcel