PHP export report (case)

Source: Internet
Author: User
You need to write your own reports to achieve the report effect. The main idea is that thulu can achieve other effects. Count the number of people who arrive late and leave early every day of the year. Effect

Requirement

You need to write your own reports to achieve the report effect.

The main idea is that thulu can achieve other effects.

Count the number of people who arrive late and leave early every day of the year.

Ideas

Implemented in PHP.

First, use HTML to implement the report style,

Then use the PHP header function to generate the xls download.

Knowledge Point

  • Merge columns and rows in a table

  • PHP obtains every day of the year for display.

  • PHP header function

  • Smarty template functions

  • Smarty user-defined functions

  • ...

PHP code

Public function export () {// get the 2016 date $ time_start = strtotime ('2017-01-01 '); $ time_end = strtotime ('2017-12-31 '); $ month_arr = []; $ month_arr ['month'] [] = '2014-01 '; $ month_arr ['numbers'] [] = date ('t ', $ time_start); // get the number of days while ($ time_start = strtotime ('+ 1 month', $ time_start) <= $ time_end) {$ month_arr ['month'] [] = date ('Y-M', $ time_start ); // get incremental month $ month_arr ['numbers '] [] = date ('t', $ time_start); // Get days} function check_week ($ time = []) {if (empty ($ time ['day']) {return '';} $ w = intval (date ('W ', strtotime ($ time ['day']); if ($ w = 0 | $ w = 6) {return''. Date ('D', strtotime ($ time ['day']).'';} Return''. Date ('D', strtotime ($ time ['day']).'';} // Register a function $ this-> smarty-> registerPlugin ('function', 'Check _ week', 'Check _ week ') with the template '); // the simulated data is as follows: $ list [0] ['name'] = 'Tom '; $ list [1] ['name'] = 'job '; $ list [0] ['sex'] = 'male'; $ list [1] ['sex'] = 'female '; $ list [0] ['age'] = '30'; $ list [1] ['age'] = '31 '; // Set to late $ list [0] ['late'] = ['2017-01-08 ', '2017-01-09', '2017-02-09 ', '2017-03-09 ', '2017-04-09 ', '2017-05-09']; $ list [1] ['late'] = ['2017-02-12 ', '2017-03-15 ', '2017-04-13 ', '2017-05-19', '2017-05-19 ']; // set early leave $ list [0] ['leave '] = ['2017-03-09', '2017-04-11 ', '2017-05-15', '2017-06-18 ', '2017-07-21 ', '2017-08-23', '2017-09-22 ', '2017-10-20', '2017-11-17 ', '2017-12-14',]; $ list [1] ['leave '] = ['2017-05-09', '2017-06-11 ', '2017-07-13', '2017-08-15 ', '2017-09-17 ', '2017-10-19', '2017-11-20 ', '2017-12-23', '2017-03-18 ', '2017-02-19 ', '1970-01-23 ',]; $ file_name = "report -". date ("YmdHis", time (); $ file_suffix = "xls"; header ("Content-Type: application/vnd. ms-excel "); header (" Content-Disposition: attachment; filename = $ file_name. $ file_suffix "); $ this-> _ assign ('list', $ list); $ this-> _ assign ('month', $ month_arr ); $ this-> _ display ();}

HTML code

    
     
     
 
 
 {If $ month} {foreach $ month. month as $ k => $ m} 
    {/Foreach} {/if} 
   
     {If $ month} {foreach $ month. month as $ k =>$ m} {section name = count loop = $ month. numbers. $ k + 1 start = 1} {check_week day = $ m | cat: "-" | cat: $ smarty. section. count. index} {/section} {/foreach} {/if} 
   {If $ list} {foreach $ list as $ s} 
   {If $ month} {foreach $ month. month as $ k =>$ m} {section name = count loop = $ month. numbers. $ k + 1 start = 1} {if $ smarty. section. count. index <10} {$ str = ""} {$ smarty. section. count. index = $ str | cat: "0" | cat: $ smarty. section. count. index} {/if} 
    {/Section} {/foreach} {/if} 
   {/Foreach} 
   {/If} 
  
Name Gender Age {$ M}
{$ S. name | default :'--'} {$ S. sex | default :'--'} {$ S. age | default :'--'}{If $ s ['late']} {if ($ m | cat: "-" | cat: $ smarty. section. count. index) | in_array: $ s ['late']} 1 {/if} {if $ s ['leave ']} {if ($ m | cat: "-" | cat: $ smarty. section. count. index) | in_array: $ s ['leave ']} 1 {/if}
* Weekend
* Normal
* Late
* Leave early

The above is the content of the PHP export report (case). For more information, see The PHP Chinese website (www.php1.cn )!

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.