码迷,mamicode.com
首页 > Web开发 > 详细

php write excel

时间:2015-12-21 18:08:44      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

/**
 * 写excel方法
 */
function writeExcel($tabArr, $dataArr,$path) {
    require_once CODE_BASE2 . ‘/util/phpexcel/PHPExcel.php‘;

    $objPHPExcel = new PHPExcel();
    $objSheet = $objPHPExcel->setActiveSheetIndex(0);

    //写表头
    $index = ‘A‘;
    foreach ($tabArr as  $value) {
        $objSheet->setCellValue($index .‘1‘, $value);
        $index++;
    }

    //写数据
    $i = 2;
    foreach ($dataArr as $key => $line) {
        $index = ‘A‘;
        foreach($line as $val){
            $objSheet->setCellValue($index.$i, $val);
            $index++;
        }
        $i++;
    }

    $objWriter = PHPExcel_IOFactory:: createWriter($objPHPExcel, ‘Excel2007‘);
    $objWriter->save($path);
}

 

php write excel

标签:

原文地址:http://www.cnblogs.com/zhudongchang/p/5063987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!