Home > php教程 > php手册 > body text

输出EXCEL文件

WBOY
Release: 2016-06-06 19:31:51
Original
1725 people have browsed it

使用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;
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!