phpexcel讀1

<?php
require_once 'Classes/PHPExcel.php';
$fileName = '1.xls';
$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() )."\t";
}
echo "<br />";
}
?>php

相關文章
相關標籤/搜索