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

WBOY
Libérer: 2016-06-23 13:34:20
original
1418 Les gens l'ont consulté

 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     echo '11         <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                    echo '24                    <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 echo '40             </tbody>41         </table>42     ';43 ?>
Copier après la connexion

 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`) VALUES13 (1, 'a', '小张'),14 (2, 'a', '小孙'),15 (3, 'b', '小王'),16 (4, 'c', '小李'),17 (5, 'a', '小红'),18 (6, 'b', '小赵');
Copier après la connexion

 功能实现预览:

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!