zoukankan      html  css  js  c++  java
  • PHPEXCEL导入小技巧

    在导入excel的时候,单元格格式和公式经常让导入不顺畅。注意phpexcel文档说明,基本上就可以很顺利的导入。

    1、忽略单元格格格式,并导入xls、xlsx两种格式

    $objReader = PHPExcel_IOFactory::createReaderForFile("abc.xlsx");//xls、xlsx格式都可导入
    $objReader->setReadDataOnly(true);//忽略单元格格式
    $PHPExcel = $objReader->load("abc.xlsx");

    2、忽略公式

    $currentSheet = $PHPExcel->getSheet(0);
    $val = $currentSheet->getCellByColumnAndRow($column,$currentRow)->getValue();
    if(substr($val,0,1) == "="){//判断是不是公式
        $val = $currentSheet->getCellByColumnAndRow($column,$currentRow)->getCalculatedValue();
    }

    3、再插入一点PHPEXCEL跟YII结合的方法

    spl_autoload_unregister ( array (
            'YiiBase',
            'autoload'
       ) );
     $phpExcelPath = Yii::getPathOfAlias ( 'ext.phpexcel' );
     include ($phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php');
     spl_autoload_register ( array (
         'YiiBase',
         'autoload'
      ) );
      $objReader = PHPExcel_IOFactory::createReader ( 'Excel5' ); // 2003格式的
      $objReader->setReadDataOnly ( true );
            
      $file_name = $file->tempName;
      $objPHPExcel = $objReader->load ( $file_name );
      $objWorksheet = $objPHPExcel->getActiveSheet ();
  • 相关阅读:
    spring和mybatis的结合
    SpringMVC
    springdata
    springboot的总结
    SpringAop代理模式笔记
    springcloud
    完全二叉树和满二叉树
    C# 读取EXCEL文件的三种经典方法
    C#加密app.config中连接字符串的代码
    c#winform 程序 App.config文件加密(SDK命令)
  • 原文地址:https://www.cnblogs.com/zhrea/p/3321578.html
Copyright © 2011-2022 走看看