export.php 1.88 KB
<?php
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
$title = date('Y-m-d').'_机器型号数据';
$name = $title.".xls";
header('Content-Disposition: attachment;filename='.$name.'');
header('Cache-Control: max-age=0');
$fp = fopen('php://output', 'a');
$limit = 5000;
$cnt=0;
ini_set('memory_limit','512M');
ini_set('max_execution_time',0);
ob_end_clean();
ob_start();
?>
<!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 x:str border='1' cellpadding='0' cellspacing='0' width='100%' style="border-collapse: collapse">
        <thead>
        <tr>
            <th width="15%">编号</th>
            <th width="25%">机器型号</th>
            <th width="25%">创建时间</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($listdata as $item) : ?>
            <tr>
                <td style="padding:12px;"><?= (isset($item["model_no"]) ? $item["model_no"] : "") ?></td>
                <td style="padding:12px;"><?= (isset($item["name"]) ? $item["name"] : "") ?>
                <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td>
            </tr>
            <?php
            $cnt ++;
            if (500 == $cnt) { //刷新一下输出buffer,防止由于数据过多造成问题
                ob_flush();
                flush();
                $cnt = 0;
            }
            ?>
        <?php endforeach;?>
         <?php ob_flush();
	        flush();
	        ob_end_clean(); 
	?>
        </tbody>
    </table>
</div>
</body>
</html>