Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to export report by PHP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to export reports from PHP". In daily operation, I believe many people have doubts about how to derive reports from PHP. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to derive reports from PHP". Next, please follow the editor to study!

Effect.

Demand

In order to achieve the effect of the report, their own made-up requirements.

Mainly is the train of thought, the train of thought has realized other effects also OK.

Count everyone who arrives late and leaves early every day of the year.

Train of thought

It is implemented in PHP language.

First of all, implement the report style with HTML

Then use the PHP header function to generate xls downloads.

Knowledge point

Column merge and row merge in a table

PHP acquires every day of the year to show

PHP header function

Smarty template function

Smarty custom function

...

PHP code

Public function export () {/ / get the 2016 date $time_start = strtotime ('2016-01-01'); $time_end = strtotime ('2016-12-31'); $month_arr = []; $month_arr ['month'] [] =' 2016-01; $month_arr ['numbers'] [] = date / / get the number of days while (($time_start = strtotime ('+ 1 month', $time_start)) smarty- > registerPlugin ('function','check_week','check_week'); / / simulated data are as follows: $list [0] [' name'] = 'Tom'; $list [1] [' name'] = 'Joan'; $list [0] [' sex'] = 'male'; $list [1] ['sex'] =' female' $list [0] ['age'] =' 30 minutes; $list [1] ['age'] =' 31 minutes; / / set late $list [0] ['late'] = [' 2016-01-08, '2016-01-09,' 2016-02-09, '2016-03-09,' 2016-04-09, '2016-05-09] $list [1] ['late'] = [' 2016-02-12, '2016-03-15,' 2016-04-13, '2016-05-19,' 2016-05-19'] / / set early departure $list [0] ['leave'] = [' 2016-03-09, '2016-04-11,' 2016-05-15, '2016-06-18,' 2016-07-21, '2016-08-23,' 2016-09-22, '2016-10-20,' 2016-11-17' '2016-12-14,] $list [1] ['leave'] = [' 2016-05-09, '2016-06-11,' 2016-07-13, '2016-08-15,' 2016-09-17, '2016-10-19,' 2016-11-20, '2016-12-23, 2016-03-18' '2016-02-19,' 2016-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

Name

Gender

Age

{if $month} {foreach $month.month as $k = > $m}

{$m}

{/ foreach} {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 } {$s.name | default:'--'} {$s.sex | default:'--'} {$s.age | default:'--'} {if $month} {foreach $month.month as $k = > $m} {section name=count loop=$month.numbers.$k+1 start=1} {if $smarty.section.count.index

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report