tp3使用PHPExcel 导出excel

时间:2020-09-05 04:12:19 来源:

【摘要】 tp3使用PHPExcel 导出excel考必过小编为大家整理了关于tp3使用PHPExcel 导出excel的信息,希望可以帮助到大家!

tp3使用PHPExcel 导出excel

标签:stringwriterreacrow数据columndatesheetmax

/**
 * 通用导出
 * array $data 导出数据
 * array $indexKey 导出数据键
 * array $headArr 表头
 * string $title 生成文件名
 *
 * 必须保持 $indexKey 和 $headArr 顺序对应才能保证导出数据准确
 */
function plainExportExcel($data,$indexKey,$headArr,$title)
{
    //引入核心文件
    import("Org.Util.PHPExcel");
    import("Org.Util.PHPExcel.IOFactory");
    $objPHPExcel = new \PHPExcel();
    $objWriter =  \PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel5‘);
    // 设置excel文档的属性
    $objPHPExcel->getProperties();
    $fileName = $title.date("Y-m-d",time()).".xls";
    //excel头
    $letter = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK","AL","AM","AN","AO"];
    //设置表头
    $num = 0;
    foreach($headArr as $v){
        $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($letter[$num].‘1‘, $v);
        $num ++;
    }
    $column = 2;
    $objActSheet = $objPHPExcel->getActiveSheet();
    //写入内容
    foreach($data as $key => $rows){
        //行写入
        $num = 0;
        foreach ($indexKey as $ki => $vi) {
            //列写入
            $objActSheet->setCellValue($letter[$num].$column, $rows[$vi]);
            $num++;
        }
        $column++;
    }

    $fileName = iconv("utf-8", "gb2312", $fileName);
    $objPHPExcel->setActiveSheetIndex(0);
    ob_end_clean();
    ob_start();
    Header(‘content-Type:apppcation/vnd.ms-excel;charset=utf-8‘);
    header(‘Content-Type: apppcation/vnd.ms-excel‘);
    header("Content-Disposition: attachment;filename=\"$fileName\"");
    header(‘Cache-Control: max-age=0‘);
    header(‘content-type:apppcation/octet-stream‘);
    $objWriter->save(‘php://output‘); //文件通过浏览器下载
}

tp3使用PHPExcel 导出excel

标签:stringwriterreacrow数据columndatesheetmax

以上就是tp3使用PHPExcel 导出excel的内容,更多资讯请及时关注考必过网站,最新消息小编会第一时间发布,大家考试加油!

上一篇      下一篇
前端相关推荐 更多>>
前端热点专题 更多>>
热点问答
国家公务员考试年龄限制是多少 公务员国考和省考考试内容有什么区别 函授大专学历能不能考公务员 国家公务员考试考点能自己选择吗 新闻学专业能报考2022年公务员考试吗 什么是联合培养研究生 什么是破格录取研究生 什么人不适合读研 研究生报名户口所在地填什么 研究生结业和毕业有什么区别
网站首页 网站地图 返回顶部
考必过移动版 https://m.kaobiguo.net