美文网首页
用phpExcel导出excel

用phpExcel导出excel

作者: 精神科赵主任 | 来源:发表于2019-05-08 18:16 被阅读0次
    
    <?php
    
    include_once('./Classes/PHPExcel.php');
    
    $objPHPExcel = new PHPExcel();
    
    $objSheet = $objPHPExcel->getActiveSheet();
    
    $objSheet->setTitle('demo');
    
    $data = array(
    
    array('姓名','分数'),
    
    array('李四','60'),
    
    array('王五','70')
    
    );
    
    $column = 1;
    
    foreach($data as $k => $v)
    
    {
    
        $span = ord("A");
    
        foreach($v as $vk=>$vv)
    
        {
    
            $j = chr($span);
    
            $objSheet->setCellValue($j.$column, $vv);
    
            $span++;
    
        }       
    
        $column++;
    
    }
    
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');
    
    $dir = dirname(__FILE__);
    
    $objWriter->save($dir.'/demo.xlsx');
    
    

    相关文章

      网友评论

          本文标题:用phpExcel导出excel

          本文链接:https://www.haomeiwen.com/subject/hpvvoqtx.html