PHP implementation to get Excel file data

Source: Internet
Author: User
This article mainly introduces the method of PHP to get Excel file data. Has a good reference value. Let's take a look at the little series.

Very simple can be achieved, the following for everyone to briefly introduce the next

1, download Phpexcel class, is a folder, there must be a file phpexcel.php, two in the sibling directory

Require __dir__. './phpexcel/iofactory.php ';  $PHPReader = new \phpexcel_reader_excel2007 ();  Determine the file type  if (! $PHPReader->canread ($filePath)) {   $PHPReader = new \phpexcel_reader_excel5 ();   if (! $PHPReader->canread ($filePath)) {    echo ' no Excel ';    return false;   }  }  $PHPExcel = $PHPReader->load ($filePath);  /** read the first worksheet in an Excel file *  /$currentSheet = $PHPExcel->getsheet (0);  /** gets the largest column number *  /$allColumn = $currentSheet->gethighestcolumn ();  /** get total number of lines *  /$allRow = $currentSheet->gethighestrow ();  /** output from line 1th *  /for ($currentRow = 1; $currentRow <= $allRow; $currentRow + +) {   /** start output from column A *   /for ($ Currentcolumn = ' A '; $currentColumn <= $allColumn; $currentColumn + +) {    $val = $currentSheet->getcellbycolumnandrow (ord ($currentColumn)-+, $currentRow) GetValue ();    /**ord () Converts the character to a decimal number */    $date [$currentRow -1][] = $val;   }  }  return $date;

The above is the whole content of this article, I hope that everyone's study has helped.


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.