export.php 2.67 KB
<?php

use domain\upgrade\UpgradeLogStatus;

header('Content-Type: application/vnd.ms-excel;charset=utf-8');
$title = iconv('UTF-8','GBK','机器状态统计数据');
$name = $title . ".xls";
header('Content-Disposition: attachment;filename=' . $name . '');
header('Cache-Control: max-age=0');
$fp = fopen('php://output', 'a');
$limit = 10000;
$cnt = 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:x="urn:schemas-microsoft-com:office:excel"
      xmlns="http://www.w3.org/TR/REC-html40">

<head>
    <meta http-equiv=Content-Type content="text/html; charset=utf-8">

</head>
<body>
<div id="Classeur1_16681" align='center' x:publishsource="Excel">
    <table border='1' cellpadding='0' cellspacing='0' width='100%' style="border-collapse: collapse">
        <thead>
        <tr>
            <th width="10%">设备ID</th>
            <th width="10%">Barcode</th>
            <th width="10%">软件版本</th>
            <th width="10%">硬件版本</th>
            <th width="10%">厂商</th>
            <th width="10%">设备型号</th>
            <th width="10%">所在城市</th>
            <th width="10%">IP地址</th>
            <th width="15%">时间</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($listdata as $key => $item) : ?>
            <tr>
                <td style="padding:12px;"><?= (isset($item["device_id"]) ? $item["device_id"] : "-") ?></td>
                <td style="padding:12px;"><?= (isset($item["barcode"]) ? $item["barcode"] : "-") ?></td>
                <td style="padding:12px;"><?= (isset($item["software_version"]) ? $item["software_version"] : "-") ?></td>
                <td style="padding:12px;"><?= (isset($item["hardware_version"]) ? $item["hardware_version"] : "-") ?></td>
                <td style="padding:12px;"><?= (isset($item["manufacture_name"]) ? $item["manufacture_name"] : "-") ?></td>
                <td style="padding:12px;"><?= (isset($item["model_name"]) ? $item["model_name"] : "") ?></td>
                <td style="padding:12px;"><?= empty($item["city"])? '-':$item["city"]?></td>
                <td style="padding:12px;"><?= $item["ip"]?></td>
                <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['timestamp'])?></td>
            </tr>
            <?php
            $cnt++;
            if (1000 == $cnt) { //刷新一下输出buffer,防止由于数据过多造成问题
                ob_flush();
                flush();
                $cnt = 0;
            }
            ?>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
</body>
</html>