<?php
Require_once ' classes/phpexcel.php ';
$fileName = ' 1.xls ';
$path = ";
$filePath = $path. $fileName;
$PHPExcel = new Phpexcel ();
$PHPReader = new phpexcel_reader_excel2007 ();
In order to be able to read all versions of Excel files
if (! $PHPReader->canread ($filePath))
{
$PHPReader = new Phpexcel_reader_excel5 ();
if (! $PHPReader->canread ($filePath))
{
Echo ' didn't find Excel file! ‘;
Return
}
}
No need to read the entire Excel file and get all the worksheet array function, feel this function is very useful, find a half a day to find
$sheetNames = $PHPReader->listworksheetnames ($filePath);
Reading Excel files
$PHPExcel = $PHPReader->load ($filePath);
Get the number of worksheets
$sheetCount = $PHPExcel->getsheetcount ();
Select the first worksheet
$currentSheet = $PHPExcel->getsheet (0);
How many columns are obtained?
$allColumn = $currentSheet->gethighestcolumn ();
How many lines are there to get altogether
$allRow = $currentSheet->gethighestrow ();
Loop to read the data, the default encoding is UTF8, here to convert to GBK output
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/>";
}
?>