Read the Excel file and have to read column A

Source: Internet
Author: User
Read Excel file, only read column A

function Import_excel ($filePath) {
$txt =array ();
$PHPReader = new phpexcel_reader_excel2007 ();
if (! $PHPReader->canread ($filePath)) {
$PHPReader = new Phpexcel_reader_excel5 ();
if (! $PHPReader->canread ($filePath)) {
Echo ' no Excel ';
return;
}
}

Create an Excel object where you can read the file from an Excel object, or write it to a file
$PHPExcel = $PHPReader->load ($filePath);

/** reading the first worksheet in an Excel file */
$currentSheet = $PHPExcel->getsheet (0);
/** get the largest column number */
$allColumn = $currentSheet->gethighestcolumn ();
How many lines does the/** get altogether? */
$allRow = $currentSheet->gethighestrow ();
echo "Allcolumn:". $allColumn. "
";
echo "Allrow:". $allRow. "
";
Iterates through the contents of each cell. Note that the row starts at 1 and the column starts from a
for ($rowIndex =1; $rowIndex <= $allRow; $rowIndex + +) {
for ($colIndex = ' A '; $colIndex <= $allColumn; $colIndex + +) {
echo $colIndex. ",";
$addr = $colIndex. $rowIndex;
$cell = $currentSheet->getcell ($addr)->getvalue ();
$txt [$rowIndex][]= $cell;
Echo $cell, ",";
}
echo "
";

}

return $txt;
}


Can only read the contents of column A, the following are not read, the examples on the Internet are like this
Is it for ($colIndex = ' a '; $colIndex <= $allColumn; $colIndex + +) to transcode A?
------to solve the idea----------------------
Please do not mislead, landlord's code and no big problem
for ($i = ' A '; $i! = ' AA '; $i + +) echo $i;
Abcdefghijklmnopqrstuvwxyz



References: For
($colIndex = ' A '; $colIndex <= $allColumn; $colIndex + +) {

$colIndex = ' A ';
$colIndex + +

A is a character, and the Execute + + will only be displayed as 1.
So every time it's 1.

Change to
for ($colIndex =0; $colIndex <= $allColumn; $colIndex + +) {
Try

------to solve the idea----------------------
References:
please do not mislead, landlord's code and no big problem
for ($i = ' A '; $i! = ' AA '; $i + +) echo $i;
Abcdefghijklmnopqrstuvwxyz



Quote: References:

for ($colIndex = ' A '; $colIndex <= $allColumn; $colIndex + +) {

$colIndex = ' A ';
$colIndex + +

A is a character, and the Execute + + will only be displayed as 1.
So every time it's 1.

Change to
for ($colIndex =0; $colIndex <= $allColumn; $colIndex + +) {
Try


Understand, if this problem is not here.
  • Related Article

    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.