PHP Operations Excel

Source: Internet
Author: User
Tags autoload

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.