zoukankan      html  css  js  c++  java
  • PHPExcel

    1.PHPExcel类中读取Excel文件相关函数和使用方法

    插件官网:http://phpexcel.codeplex.com/

    <?php
    require_once 'Classes/PHPExcel.php';
    $fileName = 'test.xlsx';
    $path = '替换成文件的具体路径';
    $filePath = $path.$fileName;
    $PHPExcel = new PHPExcel();        
    $PHPReader = new PHPExcel_Reader_Excel2007();
     
    //为了可以读取所有版本Excel文件
    if(!$PHPReader->canRead($filePath))
    {                        
        $PHPReader = new PHPExcel_Reader_Excel5();    
        if(!$PHPReader->canRead($filePath))
        {                        
            echo '未发现Excel文件!';
            return;
        }
    }
     
    //不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
    $sheetNames  = $PHPReader->listWorksheetNames($filePath);
     
    //读取Excel文件
    $PHPExcel = $PHPReader->load($filePath);
     
    //获取工作表的数目
    $sheetCount = $PHPExcel->getSheetCount();
     
    //选择第一个工作表
    $currentSheet = $PHPExcel->getSheet(0);
     
    //取得一共有多少列
    $allColumn = $currentSheet->getHighestColumn();   
     
    //取得一共有多少行
    $allRow = $currentSheet->getHighestRow();  
     
    //循环读取数据,默认编码是utf8,这里转换成gbk输出
    for($currentRow = 1;$currentRow<=$allRow;$currentRow++)
    {
        for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++)
        {
            $address = $currentColumn.$currentRow;
            echo iconv( 'utf-8','gbk', $currentSheet->getCell($address)->getValue() )."	";
        }
        echo "<br />";
    }
    ?>
  • 相关阅读:
    ajax-分页查询
    Bootstrap-响应式表格
    ajax-三级联动
    ajax(加载数据)
    HDU 3086 马拉车模板
    Power Strings POJ2406 KMP 求最小循环节
    KMP模板题 Number Sequence HDU1711
    Phone List HDU1671 字典树Trie
    一些linux"基本操作"的教程汇总
    Codeforces 899F Letters Removing 线段树/树状数组
  • 原文地址:https://www.cnblogs.com/cncz/p/3650079.html
Copyright © 2011-2022 走看看