Excel文檔內容:
1 | yangyu | 136123 | [email protected] |
2 | hercules | 124124 | [email protected] |
3 | northwood | 123124 | [email protected] |
<?php
require_once './Classes/PHPExcel.php';
require_once './Classes/PHPExcel/IOFactory.php';
require_once './Classes/PHPExcel/Reader/Excel5.php';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');//use excel2007 for 2007 format
$objPHPExcel = $objReader->load('./test.xlsx');
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow(); //取得總行數
$highestColumn = $sheet->getHighestColumn(); //取得總列數
//$cellValue = $objPHPExcel->getActiveSheet()->getCell('B1')->getValue();
for($j=1;$j<=$highestRow;$j++) //從第一行開始讀取數據
{
for($k='A';$k<=$highestColumn;$k++) //從A列讀取數據
{
echo $objPHPExcel->getActiveSheet()->getCell("$k$j")
->getValue().' | ';//讀取單元格
}
echo '<br>';
}
$dataArray = $objPHPExcel->getActiveSheet()
->rangeToArray(
'A1:D3', // The worksheet range that we want to retrieve
NULL, // Value that should be returned for empty cells
TRUE, // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell)
TRUE, // Should values be formatted (the equivalent of getFormattedValue() for each cell)
TRUE // Should the array be indexed by cell row and cell column
);
echo '<pre>';
print_r ($dataArray);
echo '</pre>';
exit; //debug-------------------