Phpexcel Reading 1

Source: Internet
Author: User

<?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/>";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.