支付宝赞助帐号:service@kuitao8.com 

phpexcel生成复杂的表头

Created2019-05-10   Views 53    Author 懒人程序
  public function text2(){
        $objPHPExcel= new \PHPExcel();
        $objPHPExcel->getActiveSheet()->getStyle('A1:L4')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle('A1:L4')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->setTitle('测试表格');
        $objPHPExcel->getActiveSheet()->mergeCells('A1:A3')->setCellValue('A1','日期');
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->setCellValue('B1','班次');
        $objPHPExcel->getActiveSheet()->setCellValue('B2','班次');
        $objPHPExcel->getActiveSheet()->mergeCells('B1:B3');
        $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->setCellValue('C1','总营收');
        $objPHPExcel->getActiveSheet()->setCellValue('C2','总营收');
        $objPHPExcel->getActiveSheet()->mergeCells('C1:C3');
        $objPHPExcel->getActiveSheet()->getStyle('C1')->applyFromArray(
            array(
                'fill' => array(
                    'type' => \PHPExcel_Style_Fill::FILL_SOLID,
                    'color' => array('rgb' => 'FFE699')
                )
            )
        )->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('D1')->applyFromArray(
            array(
                'fill' => array(
                    'type' => \PHPExcel_Style_Fill::FILL_SOLID,
                    'color' => array('rgb' => 'FCCFCF')
                )
            )
        );
        $objPHPExcel->getActiveSheet()->setCellValue('D2','实收款');
        $objPHPExcel->getActiveSheet()->setCellValue('D2','转帐类');
        $objPHPExcel->getActiveSheet()->setCellValue('D3','微信');
        $objPHPExcel->getActiveSheet()->setCellValue('E3','支付宝');
        $objPHPExcel->getActiveSheet()->setCellValue('F2','现金');
        $objPHPExcel->getActiveSheet()->setCellValue('F3','现金');
        $objPHPExcel->getActiveSheet()->mergeCells('F2:F3');
        $objPHPExcel->getActiveSheet()->getStyle('F2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->setCellValue('G2','手动结算');
        $objPHPExcel->getActiveSheet()->setCellValue('H2','自动结算');
        $objPHPExcel->getActiveSheet()->setCellValue('G3','小程序');
        $objPHPExcel->getActiveSheet()->setCellValue('H3','扫码支付');
        $objPHPExcel->getActiveSheet()->setCellValue('I3','pos刷卡');
        $objPHPExcel->getActiveSheet()->setCellValue('J3','团购验券');
        $objPHPExcel->getActiveSheet()->setCellValue('K2','其他');
        $objPHPExcel->getActiveSheet()->setCellValue('L2','合计');
        $objPHPExcel->getActiveSheet()->mergeCells('D1:L1');
        $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->setCellValue('D1',"实收款");
        $objPHPExcel->getActiveSheet()->mergeCells('D2:E2');
        $objPHPExcel->getActiveSheet()->getStyle('D2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->setCellValue('D2',"转账类");
        $objPHPExcel->getActiveSheet()->mergeCells('H2:J2');
        $objPHPExcel->getActiveSheet()->setCellValue('H2',"自动结算");
        $objPHPExcel->getActiveSheet()->getStyle('H2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $fileName = '测试表格' . '.xls';
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-excel;");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header("Content-Disposition:attachment;filename=" . $fileName);
        header("Content-Transfer-Encoding:binary");
        $objWriter->save('php://output');
    }
上一篇: php生成订单号
下一篇:没有了
支持键盘 ← →

邮件订阅

订阅我们的精彩内容