PHP implementation to obtain excel file data

墨辰丷
Release: 2023-03-27 17:26:01
Original
2576 people have browsed it

This article mainly introduces the method of obtaining excel file data in php. Has very good reference value. Let’s take a look at it with the editor.

It’s very simple to implement. Here’s a brief introduction for you

1. Download the PHPExcel class, which is a folder and must have One file PHPExcel.php, two in the same directory

require __DIR__ . './PHPExcel/IOFactory.php';

  $PHPReader = new \PHPExcel_Reader_Excel2007();

  //判断文件类型
  if (!$PHPReader->canRead($filePath)) {
   $PHPReader = new \PHPExcel_Reader_Excel5();

   if (!$PHPReader->canRead($filePath)) {
    echo 'no Excel';
    return false;
   }
  }

  $PHPExcel = $PHPReader->load($filePath);
  /**读取excel文件中的第一个工作表*/

  $currentSheet = $PHPExcel->getSheet(0);
  /**取得最大的列号*/

  $allColumn = $currentSheet->getHighestColumn();
  /**取得一共有多少行*/

  $allRow = $currentSheet->getHighestRow();

  /**从第1行开始输出*/
  for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {

   /**从第A列开始输出*/
   for ($currentColumn = &#39;A&#39;; $currentColumn <= $allColumn; $currentColumn++) {
    $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
    /**ord()将字符转为十进制数*/
    $date[$currentRow - 1][] = $val;
   }

  }
  return $date;
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone learning helps.


Related recommendations:

PHP Implemented browser inspection class_php skills

PHP Implemented browser inspection class _php skills

PHP Implemented through parameters Generate a complete instance of MYSQL statement class_php tips

The above is the detailed content of PHP implementation to obtain excel file data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!