zoukankan      html  css  js  c++  java
  • php操作EXCLE(通过phpExcle实现读excel数据)

    <?php
    require_once('/PHPExcel/Reader/Excel2007.php');
    $objReader = new PHPExcel_Reader_Excel2007;
    $PHPExcel = $objReader->load('testExcel.xls');

    /**
     * 读取excel文件中的第一个工作表
     */
    $currentSheet = $PHPExcel->getSheet(0);
    /**
     * 取得最大的列号
     */
    $allColumn = $currentSheet->getHighestColumn();
    /**
     * 取得总行数
     */
    $allRow = $currentSheet->getHighestRow();

    /**
     * 从第2行开始输出
     */
    for($currentRow = 1; $currentRow<=$allRow;$currentRow++){
        //从第A列开始输出
        for($currentColumn="A";$currentColumn<=$allColumn;$currentColumn++){
            $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn)-65,$currentRow)->getValue();
            if($currentColumn == 'A'){
                echo $val;
                //echo GetDate($val)." ";
            }else{
                //echo $val;
                //如果输出汉字有乱码,则需要将输出内容用iconv函数进行编码转换,如下将gb2312编码转换为utf8
                echo iconv('utf-8','gb2312',$val);
            }
            echo "   ";
        }
        echo "<br>";
    }

  • 相关阅读:
    jsp转向
    什么是 XDoclet?
    tomcat中的几点配置说明
    mysql5问题
    POJ 3734 Blocks
    POJ 2409 Let it Bead
    HDU 1171 Big Event in HDU
    POJ 3046 Ant Counting
    HDU 2082 找单词
    POJ 1286 Necklace of Beads
  • 原文地址:https://www.cnblogs.com/tangchuanyang/p/3899261.html
Copyright © 2011-2022 走看看