首页 > php教程 > php手册 > 输出EXCEL文件

输出EXCEL文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-06 19:31:51
原创
1834 人浏览过

使用php读取excel文件 PHP PHPExcel ?phprequire_once( FCPATH.'vendor/Excel/excel/PHPExcel/IOFactory.php');function readexcel( $filePath) { $PHPReader = new PHPExcel_Reader_Excel5(); if(!$PHPReader-canRead($filePath)){ $PHPReader = new PHPExce

使用php读取excel文件 PHP PHPExcel
<?php
require_once( FCPATH.'vendor/Excel/excel/PHPExcel/IOFactory.php');

function readexcel( $filePath) { 
$PHPReader = new PHPExcel_Reader_Excel5();
         if(!$PHPReader->canRead($filePath)){   
             $PHPReader = new PHPExcel_Reader_Excel5();   
                   if(!$PHPReader->canRead($filePath)){         
                        echo 'no Excel';  
                         return ;   
                   }  
          }

$PHPExcel = $PHPReader->load($filePath);  

$currentSheet = $PHPExcel->getSheet(0);  /**取得一共有多少列*/ 

$allColumn = $currentSheet->getHighestColumn();     /**取得一共有多少行*/  

$allRow = $currentSheet->getHighestRow();

$all = array();
for( $currentRow = 1 ; $currentRow <= $allRow ; $currentRow++){

          $flag = 0;
          $col = array();
          for($currentColumn='A'; getascii($currentColumn) <= getascii($allColumn) ; $currentColumn++){
             
                $address = $currentColumn.$currentRow;   

                $string = $currentSheet->getCell($address)->getValue();
                
                $col[$flag] = $string;

                $flag++;
          } 

      $all[] = $col;
}

return $all;
}

function getascii( $ch) {
  if( strlen( $ch) == 1)
    return ord( $ch)-65;
  return ord($ch[1])-38;
}
登录后复制
相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
#####为什么没输出
来自于 1970-01-01 08:00:00
0
0
0
默认输出类型为json,如何输出html
来自于 1970-01-01 08:00:00
0
0
0
javascript 输出的值
来自于 1970-01-01 08:00:00
0
0
0
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板