zoukankan      html  css  js  c++  java
  • php原生导出简单word表格(TP为例) (原)

     

    后台:

    # 菲律宾名单word导出
        public function export_word(){
                $tids = $_GET['tids'];
                $userinfo=M("philippines_visa")->where(["philippines_id"=>$tids])->select();
                foreach ($userinfo as $key => $value) {
                    $userinfo[$key]['birth'] = explode('-', $value['date_of_birth']);   # 出生日期
                    $userinfo[$key]['birth_m'] = $this->get_month($userinfo[$key]['birth']['1']);#月份英文
                    $userinfo[$key]['lssue'] = explode('-', $value['lssue_date']);      # 签发日期
                    $userinfo[$key]['lssue_m'] = $this->get_month($userinfo[$key]['lssue']['1']);#月份英文
                    $userinfo[$key]['expiration'] = explode('-', $value['expiration_date']); # 有效日期
                    $userinfo[$key]['expiration_m'] = $this->get_month($userinfo[$key]['expiration']['1']);#月份英文
                }
                $user_info = $userinfo;
                $user_info = array_chunk($user_info, 20, true); # 拆分为20个元素一组的多维数组 (需求而已)
                $this->assign('user_info',$user_info);
                $filename = '名单';
                ob_start(); //打开缓冲区
                $this->display();
                header("Cache-Control: public");
                Header("Content-type: application/octet-stream");
                Header("Accept-Ranges: bytes");
                if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) {
                    header('Content-Disposition: attachment; filename='.$filename.'.doc');
                }else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) {
                    Header('Content-Disposition: attachment; filename='.$filename.'.doc');
                } else {
                    header('Content-Disposition: attachment; filename='.$filename.'.doc');
                }
                header("Pragma:no-cache");
                header("Expires:0");
                ob_end_flush();//输出全部内容到浏览器 
        }
    

    前端页面:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>菲律宾签证</title>
        <style>
            @page{
                margin: 30px;
            }
            .box{page-break-after:always;}
            input{font-family: '宋体';}
            table{
                 border-collapse: collapse;     /*设置列、行间距*/
            }
            table td,table th{
                text-align:center;
            }
        </style>
    </head>
    <body>
    <!-- 名单模板三 -->
                <foreach name="user_info" item="user_page" key="key">
                        <div class="box box7 page" style="border-bottom:none;">
                            <table>
                                <tr>
                                    <th style="4%;border:1px solid #000"></th>
                                    <th style="10%;border:1px solid #000">SURNAME</th>
                                    <th style="12%;border:1px solid #000">GIVEN NAME</th>
                                    <th style="5%;border:1px solid #000">SEX</th>
                                    <th style="5%;border:1px solid #000">(Birth Month) MM</th>
                                    <th style="5%;border:1px solid #000">(Birth Day) DD</th>
                                    <th style="5%;border:1px solid #000">(Birth Year) YY</th>
                                    <th style="12%;border:1px solid #000">Passport Number</th>
                                </tr>
                                <tbody class="">
                                    <foreach name="user_page" item="vo" key="k">
                                        <tr>
                                            <td style="border:1px solid #000">{$k+1}</td>
                                            <td style="border:1px solid #000">{$vo.english_name}</td>
                                            <td style="border:1px solid #000">{$vo.english_name_s}</td>
                                            <td style="border:1px solid #000"><eq name='vo.m_sex' value='男'>M<else />F</eq></td>
                                            <td style="border:1px solid #000">{$vo['birth']['1']}</td>
                                            <td style="border:1px solid #000">{$vo['birth']['2']}</td>
                                            <td style="border:1px solid #000">{$vo['birth']['0']}</td>
                                            <td style="border:1px solid #000">{$vo.m_visa_number}</td>
                                        </tr>
                                    </foreach>
                                </tbody>
                            </table>
                        </div>
                    </foreach>
    </body>
    </html>                
    

     呈现:

  • 相关阅读:
    Practice3_5_vector_sort_struct_gold_silver_bronze_playerName1
    Practice3_4_vector_sort_struct_string
    Practice3_3_vector_sort_struct
    Practice3_2_vector_sort_struct
    2017多校第9场 HDU 6170 Two strings DP
    BZOJ 3771 生成函数,FFT
    BZOJ 3028 食物 生成函数
    Codeforces Round #428 (Div. 2) 题解
    2017中国大学生程序设计竞赛
    2017多校第8场 HDU 6133 Army Formations 线段树合并
  • 原文地址:https://www.cnblogs.com/gyrgyr/p/11777805.html
Copyright © 2011-2022 走看看