PHPexcel表格格式调整

public function send_export(){
        Loader::import('PHPExcel.Classes.PHPExcel');
        Loader::import('PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
        Loader::import('PHPExcel.Classes.PHPExcel.Reader.Excel2007');
        Loader::import('PHPExcel.Classes.PHPExcel.Reader.Excel5');
        $obj = new \PHPExcel();

        $obj->getActiveSheet(0)->setTitle('sheet1');   //设置sheet名称
        $activeSheet = $obj->getActiveSheet();
        $activeSheet->mergeCells('A1:G1');
        $activeSheet->mergeCells('A2:G2');
        $activeSheet->mergeCells('B5:C5');
        $activeSheet->mergeCells('B6:C6');
        $activeSheet->mergeCells('B7:C7');
        $activeSheet->mergeCells('D5:E5');
        $activeSheet->mergeCells('D6:E6');
        $activeSheet->mergeCells('D7:E7');
        $activeSheet->mergeCells('F5:G5');
        $activeSheet->mergeCells('F6:G6');
        $activeSheet->mergeCells('F7:G7');

        $obj->getDefaultStyle()->getFont()->setName('微软雅黑');//字体
        $obj->getActiveSheet()->getStyle('A1:G7')->getAlignment()
            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);//文字居中
        $obj->getActiveSheet()->getStyle('A1:G2')->getFont()->setSize(14);//字体大小
        $activeSheet->getDefaultColumnDimension()->setWidth(11);
        $obj->getActiveSheet()->getRowDimension(1)->setRowHeight(55);
        $obj->getActiveSheet()->getRowDimension(2)->setRowHeight(55);
        $obj->getActiveSheet()->getRowDimension(3)->setRowHeight(55);
        $obj->getActiveSheet()->getRowDimension(4)->setRowHeight(55);
        $obj->getActiveSheet()->getRowDimension(5)->setRowHeight(55);
        $obj->getActiveSheet()->getRowDimension(6)->setRowHeight(55);
        $obj->getActiveSheet()->getRowDimension(7)->setRowHeight(55);

        //所有垂直居中
        $obj->getActiveSheet()->getStyle('A1:G7')
            ->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);

        //***********************画出单元格边框*****************************
        $styleArray = array(
            'borders' => array(
                'allborders' => array(
                    //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                    'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
                    //'color' => array('argb' => 'FFFF0000'),
                ),
            ),
        );
        $activeSheet->getStyle('A1:G7')->applyFromArray($styleArray);//这里就是画出从单元格A5到N5的边框,看单元格最右边在哪哪个格就把这个N改为那个字母替代
        //***********************画出单元格边框结束*****************************


        $obj->setActiveSheetIndex(0)->setCellValue('A1', '我们的有限公司');
        $obj->getActiveSheet(0)->setCellValue('A2', '出货装箱单');
        $obj->getActiveSheet(0)->setCellValue('A3', '出货日期');
        $obj->getActiveSheet(0)->setCellValue('B3', '商品名称');
        $obj->getActiveSheet(0)->setCellValue('C3', '箱数');
        $obj->getActiveSheet(0)->setCellValue('D3', '出货数量/件');
        $obj->getActiveSheet(0)->setCellValue('E3', '重量/KG');
        $obj->getActiveSheet(0)->setCellValue('F3', '出货国家');
        $obj->getActiveSheet(0)->setCellValue('G3', '物流公司');
        
        // $obj->getActiveSheet(0)->setCellValue('A4', '2019-01-23');
        // $obj->getActiveSheet(0)->setCellValue('D4', '5');
        // $obj->getActiveSheet(0)->setCellValue('F4', '美国');
        // $obj->getActiveSheet(0)->setCellValue('G4', '跨境易通');


        $obj->getActiveSheet(0)->setCellValue('A5', '发货人:');
        $obj->getActiveSheet(0)->setCellValue('D5', '物流公司签名:');
        $obj->getActiveSheet(0)->setCellValue('A6', '审核:');
        $obj->getActiveSheet(0)->setCellValue('D6', '司机签字:');
        $obj->getActiveSheet(0)->setCellValue('D7', '车牌号:');

        $objWrite = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
        header('pragma:public');
        header("Content-Disposition:attachment;filename=出货装箱单.xlsx");
        $objWrite->save('php://output');
        exit;
    }

如图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值