php讀取excel

来源:互联网 发布:网络机柜跳线是什么 编辑:程序博客网 时间:2024/06/05 18:00

 使用php讀取excel需要一個reader.php文件
此處為excel_reader2.php需要下載,下載的地址為http://code.google.com/p/php-excel-reader/downloads/list

使用require_once引入excel_reader2.php

引入的代碼如下:

require_once('excel_reader2.php');

=====================================

這是我使用php提供的內置讀取Excel的類Spreadsheet_Excel_Reader
<?php
 //設置頁面編碼
 header("content-type:text/html;charset=utf-8");
 //調用reader
 require_once('excel_reader2.php');
 //創建Reader
 $data = new Spreadsheet_Excel_Reader();
 //設置文本輸出編碼
 $data->setOutputEncoding('utf-8');
 //讀取Excel文件
 $data->read("leaves.xls");
 for($i = 1;$i <= $data->sheets[0]['numRows'];$i++){//$data->sheets[0]['numRows']為Excel中有內容的行數
  for($j = 1;$j <= $data->sheets[0]['numCols'];$j++){//$data->sheets[0]['numCols']為Excel中有內容的列數
   //顯示每個單元格中的內容并換行
   echo $data->sheets[0]['cells'][$i][$j]."<br/>";
  }
 }
?>

原创粉丝点击