如何使用php获取excel文件数据

时间:2025-08-26 09:42:13 php语言 我要投稿

如何使用php获取excel文件数据

  文章主要介绍了php获取excel文件数据的方法。具有很好的参考价值。下面跟着小编一起来看下吧。

  1、下载PHPExcel类,是一个文件夹,还得有一个文件PHPExcel.php,两个在同级目录

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14

  15

  16

  17

  18

  19

  20

  21

  22

  23

  24

  25

  26

  27

  28

  29

  30

  31

  32

  33

  34

  35

  36

  37

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

  $PHPReader = new \PHPExcel_Reader_Excel2007();

  /pic/strong>

  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 = 'A'; $currentColumn <= $allColumn; $currentColumn++) {

  $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();

  /**ord()将字符转为十进制数*/

  $date[$currentRow - 1][] = $val;

  }

  }

  return $date;

【如何使用php获取excel文件数据】相关文章:

如何在PHP导出excel格式数据11-26

如何实现PHP获取表单数据与HTML嵌入PHP脚本01-16

PHP实现获取FLV文件的时间09-27

Access 2007中的数据如何导入Excel文件03-22

PHP如何使用curl实现数据抓取02-05

PHP如何获取表单10-26

如何使用php语言实现文件名称以及扩展名的获取02-26

PHP获取文件名称的方法12-08

如何打开php文件 php文件怎么打开01-13

  • 相关推荐