码迷,mamicode.com
首页 > Web开发 > 详细

php实现导出数据分类合并单元格功能

时间:2015-05-20 18:10:51      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

 1 <?php
 2     $conn = mysql_connect("localhost","root","root");
 3     $db = mysql_select_db("imexcel",$conn);
 4     mysql_query("set names ‘gbk‘");
 5 
 6     $query = "SELECT danwei,count(danwei) as num ,group_concat(fuze SEPARATOR ‘,‘) as gw FROM `dy` group by danwei";
 7     $result = mysql_query($query);
 8     header("Content-type:application/vnd.ms-excel;charset=GBK");
 9     header("Content-Disposition:filename=test.xls");
10     echo11         <table border="1">
12             <caption class="text-center">信息统计表</caption>
13                <thead>
14                     <tr >
15                         <th>单位</th>
16                         <th>负责人</th>
17                     </tr>
18                </thead>
19               <tbody>
20;
21                while($row = mysql_fetch_array($result)) {
22                    $gw = explode(",",$row[‘gw‘]);
23                    echo24                    <tr>
25                        <td rowspan="‘.$row[‘num‘].‘">‘.$row[‘danwei‘].‘</td>
26                        <td>‘.iconv("gbk","utf-8",$gw[0]).‘</td>
27                    </tr>
28;
29                     if($row[‘num‘] > 1){
30                         for($i=1;$i<$row[‘num‘];$i++){
31                             echo ‘<tr><td>‘.iconv("gbk","utf-8",$gw[$i]).‘</td></tr>‘;
32                         }
33                     }else{
34 
35                     }
36 
37                }
38 
39 echo40             </tbody>
41         </table>
42;
43 ?>
 1 CREATE TABLE IF NOT EXISTS `dy` (
 2   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 3   `danwei` varchar(30) NOT NULL,
 4   `fuze` varchar(30) NOT NULL,
 5   PRIMARY KEY (`id`)
 6 ) ENGINE=MyISAM  DEFAULT CHARSET=gbk AUTO_INCREMENT=7 ;
 7 
 8 --
 9 -- 转存表中的数据 `dy`
10 --
11 
12 INSERT INTO `dy` (`id`, `danwei`, `fuze`) VALUES
13 (1, a, 小张),
14 (2, a, 小孙),
15 (3, b, 小王),
16 (4, c, 小李),
17 (5, a, 小红),
18 (6, b, 小赵);

 功能实现预览:

技术分享

php实现导出数据分类合并单元格功能

标签:

原文地址:http://www.cnblogs.com/dymg/p/4517651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!