添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
关键词: 发布时间:2019-04-11 15:16:32 浏览次数:13237
require_once dirname(__FILE__) . '/../library/PHPExcel-1.8/Classes/PHPExcel.php';
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->setActiveSheetIndex(0);
        //A-I列,垂直居中
        $objPHPExcel->getActiveSheet()->getStyle('A:I')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //设置列宽
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(16);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
//        //设置默认行高:但是下面合并的单元格不起作用
//        $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(26);
//        //设置第一行的高度
//        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
        $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(26);
        $objPHPExcel->getActiveSheet()->getRowDimension('3')->setRowHeight(6);
        $objPHPExcel->getActiveSheet()->getRowDimension('4')->setRowHeight(26);
        $objPHPExcel->getActiveSheet()->getRowDimension('5')->setRowHeight(26);
        $objPHPExcel->getActiveSheet()->getRowDimension('6')->setRowHeight(26);
        $objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(26);
        $objPHPExcel->getActiveSheet()->getRowDimension('8')->setRowHeight(26);
        $objPHPExcel->getActiveSheet()->getRowDimension('9')->setRowHeight(26);
        //合并列
        $objPHPExcel->getActiveSheet()->mergeCells('A1:C1');
        $objPHPExcel->getActiveSheet()->mergeCells('D1:I1');
        //设置字体大小及加粗
        $objPHPExcel->getActiveSheet()->setCellValue('A1', '周工作报表')
            ->getStyle('A1')->getFont()->setSize(24)->setBold(true);
        $objPHPExcel->getActiveSheet()->setCellValue('D1', '开始日期: 2019-04-08 结束日期: 2019-04-14');
        $objPHPExcel->getActiveSheet()->mergeCells('A2:B2');
        $objPHPExcel->getActiveSheet()->setCellValue('A2', '部门:技术部');
        $objPHPExcel->getActiveSheet()->mergeCells('C2:D2');
        $objPHPExcel->getActiveSheet()->setCellValue('C2', '姓名:胡熔');
        $objPHPExcel->getActiveSheet()->mergeCells('E2:F2');
        $objPHPExcel->getActiveSheet()->setCellValue('E2', '职务:php');
        $objPHPExcel->getActiveSheet()->mergeCells('G2:I2');
        $objPHPExcel->getActiveSheet()->setCellValue('G2', '填表日期:2019-04-11');
        $objPHPExcel->getActiveSheet()->mergeCells('A3:I3');
        //设置背景颜色
        $objPHPExcel->getActiveSheet()->getStyle('A3')->applyFromArray(
            array(
                'fill' => array(
                    'type' => \PHPExcel_Style_Fill::FILL_SOLID,
                    'color' => array('rgb' => 'eeeeee')
        $objPHPExcel->getActiveSheet()->setCellValue('A4', '本周总结');
        $objPHPExcel->getActiveSheet()->setCellValue('B4', '工作内容描述');
        $objPHPExcel->getActiveSheet()->setCellValue('C4', '计划完成时间');
        $objPHPExcel->getActiveSheet()->setCellValue('D4', '实际完成时间');
        $objPHPExcel->getActiveSheet()->setCellValue('E4', '完成状态');
        $objPHPExcel->getActiveSheet()->setCellValue('F4', '未完成原因分析');
        $objPHPExcel->getActiveSheet()->setCellValue('G4', '责任人');
        $objPHPExcel->getActiveSheet()->setCellValue('H4', '协助人    ');
        $objPHPExcel->getActiveSheet()->setCellValue('I4', '备注');
    $objPHPExcel->getActiveSheet()->setTitle('周工作报表');
        $filename="工作周报_{$user['Name']}_第{$weekly['Week']}周.xls";
        //生成文件
//        $objPHPExcel->setActiveSheetIndex(0);
//        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//        $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
        //直接从浏览器下载
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=0');
        header('Cache-Control: max-age=1');
        header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
        header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header ('Pragma: public'); // HTTP/1.0
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;

效果如下:

image.png

赞:( 84 )
踩:( 0 )
【github】www.github.com/hurong241
【码云】gitee.com/hu_rong/projects
【docker hub】hub.docker.com/repositories/hurong241
【packagist】packagist.org/users/hurong241/packages
建站时间:2011年
文章数:620篇
浏览数:1135615