Learning Address:
http://www.houdunren.com/houdunren18_lesson_240
Plug - ins:
Https://packagist.org/?query=phpoffice
Download plugin: Composer require phpoffice/phpspreadsheet
Manual Address:
https://phpspreadsheet.readthedocs.io/en/develop/
Environmental Requirements: Software requirements
The following software is required to develop using Phpspreadsheet:
- PHP version 5.6 or newer
- PHP extension Php_zip Enabled
- PHP extension Php_xml Enabled
- PHP extension PHP_GD2 enabled (if not compiled in)
Detection environment:
1<?PHP2 /**3 * Created by Haima.4 * Author:haima5 * qq:2286544166 * DATE:2018/7/227 * time:9:358 */9 Ten require' Vendor/autoload.php '; One A /** - * Environmental Testing - */ the - Var_dump(php_version); - Var_dump(extension_loaded(' Zip ')); - Var_dump(extension_loaded(' XML ')); + Var_dump(extension_loaded(' GD '));
You can see that the environment is fine
Write the data and save it as an Excel file:
1<?PHP2 /**3 * Created by Haima.4 * Author:haima5 * qq:2286544166 * DATE:2018/7/227 * time:9:358 */9 Ten require' Vendor/autoload.php '; One A ///** - //* Environmental Testing - // */ the // - //var_dump (php_version); - //var_dump (extension_loaded (' zip ')); - //var_dump (extension_loaded (' xml ')); + //var_dump (extension_loaded (' GD ')); - + A UsePhpoffice\phpspreadsheet\spreadsheet; at Usephpoffice\phpspreadsheet\writer\xlsx; - - $spreadsheet=NewSpreadsheet (); - $spreadsheet->setactivesheetindex (0);//set the form page to manipulate sheet, passing in an index - $sheet=$spreadsheet->getactivesheet ();//get the form that is currently being manipulated - in //Set table header - $sheet->setcellvalue (' A1 ', ' numbering ') to->setcellvalue (' B1 ', ' username ') +->setcellvalue (' B1 ', ' nickname ')) -->setcellvalue (' B1 ', ' age '); the * //the data to write $ $data= [Panax Notoginseng [ -' UID ' =>1, the' Username ' = ' lisi ', +' Nickname ' = ' John Doe ', A' Age ' =>18 the], + [ -' UID ' =>2, $' Username ' = ' Wangwu ', $' Nickname ' = ' Harry ', -' Age ' =>19 -], the [ -' UID ' =>3,Wuyi' Username ' = ' Mailiu ', the' Nickname ' = ' Hemp Six ', -' Age ' =>20 Wu ] - ]; About $sheet->fromarray ($data,NULL, ' A2 ');//start writing data from A2 line $ $writer=NewXLSX ($spreadsheet); - $writer->save (' readdata.xlsx ');//Set Save file name
Effect:
PHP Operations Excel