• phpexcel常用操作


    $objPHPExcel = new PHPExcel();
    //设置列宽
    $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth('11');


    //设置默认对齐方式
    $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    //设置默认行高
    $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);


    //设置第一行高
    $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(80);

    //合并单元格
    $objPHPExcel->getActiveSheet()->mergeCells('A1:G1');

    //设置字体
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(22);    
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');

    //设置自动换行
    $objPHPExcel->getActiveSheet()->getStyle('E10')->getAlignment()->setWrapText(true);

    //设置水平居中
    $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

    //水平居左
    $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
    //水平居右
    $objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

    //设置边框
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getTop()->getColor()->setARGB('FF000000');
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getLeft()->getColor()->setARGB('FF000000');
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getBottom()->getColor()->setARGB('FF000000');
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
    $objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getRight()->getColor()->setARGB('FF000000');    


    $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A1','')
                ->setCellValue('A2','编号:' . $BNum)
                ->setCellValue('B3',$Cz)
                ->setCellValue('G19',number_format($Czcb, 2, '.', ''))
                ->setCellValue('C20',round($Cxl,2).'%')
                ->setCellValue('E22',"鉴定评估师(签章)". $Jdpgs ." 复核人(签章) "."评估日期:".date("Y年m月d日",strtotime($Jdpgs_de)) );

    // Rename sheet
    $objPHPExcel->getActiveSheet()->setTitle('二手车鉴定评估报告单');

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    // Redirect output to a client's web browser (Excel5)

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('../excel/'. $Pg_Excel .'');



    如果想生成多个sheet

    $objPHPExcel1 = $objPHPExcel->createSheet(1);

    $objPHPExcel1->setTitle('表2');

    $objPHPExcel1->setCellValue('A1','');


    //第二张表的操作都不需要用getActiveSheet()方法了
    $objPHPExcel1->getRowDimension(1)->setRowHeight(80);

  • 相关阅读:
    android apk 防止反编译技术第二篇-运行时修改字节码
    android apk 防止反编译技术第一篇-加壳技术
    chromium浏览器开发系列第五篇:Debugging with WinDBG
    你所不知道的html5与html中的那些事(五)——web图像
    你所不知道的html5与html中的那些事(四)——文本标签
    无法导入以下密钥文件: xxxx.pfx,该密钥文件可能受密码保护 的解决方案
    GCD & LCM的一些性质
    HDU
    next
    树形结构与成环图的一个区别
  • 原文地址:https://www.cnblogs.com/shanmao/p/3286805.html
Copyright © 2020-2023  润新知