当前位置: 首页 > 工具软件 > php-xls > 使用案例 >

php导出数据xlsx

龙隐水
2023-12-01
/*
* $lists 二维数组
*/    
public function xlsx($lists)
    {
        //生成文件名
        $date = date("Y-m-d_H:i:s", time());
        $fileName = "XXXX_" . $date . ".xlsx";
        //头部标题
        $xlsx_header = array('序号', 'UID');
        ob_get_clean();
        ob_start();
        echo implode("\t", $xlsx_header),"\n";
        $num = 0;
        foreach ($lists as $key => $value) {
            $data = array();
            //序号
            $data[] = $num;
            //UID
            $data[] = $value['uid'];
            $data[] = $value['useruntwo'];
            echo implode("\t", $data),"\n";
        }
        header('Content-Disposition: attachment; filename='.$fileName);
        header('Accept-Ranges:bytes');
        header('Content-Length:' . ob_get_length());
        header('Content-Type:application/vnd.ms-excel');
        ob_end_flush();
    }
 类似资料: