PHP manipulate Excel Video Tutorials

  • PHP manipulate Excel video tutorial ( https://www.php.cn/course/422.html )

  • PHPExcel is PHP language operating Excel file most powerful tool, but also as a PHPer essential skills. "PHP manipulate Excel video tutorial" will lead us to a comprehensive analysis of import PHPexcel export, style control, graphical reporting operation to help people get along any file operation needs in future work. Recommended related video: http: //www.php.cn/jishu/php/410234.html

Article describes how to use PHP to read the content of excel file that is, each cell data, we hope to help.

 

Involving knowledge points:

①PHPExcel  is a PHP class library for manipulating Office Excel document, which is based on Microsoft's Openxml standards and PHP language. You can use it to read, write spreadsheet in different formats.

②time ()  function returns the number of seconds of the current time, the current system time used to obtain

③require_once  order to avoid duplication of the file to load the file that is loaded once

④array ()  creates an array 

⑤memory_get_usage ()  PHP built-in function to return the current amount of memory allocated to PHP scripts, use it to debug PHP code performance

⑥var_dump ()  for printing an array, or output string

03642ed68c46d7348e332462ed2140c.png

Php excel file read specific method, and the corresponding processing

Code examples are as follows:

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

<?php

/*读取excel文件,并进行相应处理*/

$fileName = "url.xls";

if (!file_exists($fileName)) {

    exit("文件".$fileName."不存在");

}

$startTime = time(); //返回当前时间的Unix 时间戳

require_once './PHPExcel/IOFactory.php';

$objPHPExcel = PHPExcel_IOFactory::load($fileName);

//获取sheet表格数目

$sheetCount = $objPHPExcel->getSheetCount();

//默认选中sheet0表

$sheetSelected = 0;$objPHPExcel->setActiveSheetIndex($sheetSelected);

//获取表格行数

$rowCount = $objPHPExcel->getActiveSheet()->getHighestRow();

//获取表格列数

$columnCount = $objPHPExcel->getActiveSheet()->getHighestColumn();

echo "<div>Sheet Count : ".$sheetCount."  行数: ".$rowCount."  列数:".$columnCount."</div>";

$dataArr = array();

 

/* 循环读取每个单元格的数据 */

//行数循环

for ($row = 1; $row <= $rowCount; $row++){

//列数循环 , 列数是以A列开始

for ($column = 'A'; $column <= $columnCount; $column++) {

    $dataArr[] = $objPHPExcel->getActiveSheet()->getCell($column.$row)->getValue();

    echo $column.$row.":".$objPHPExcel->getActiveSheet()->getCell($column.$row)->getValue()."<br />";

}

echo "<br/>消耗的内存为:".(memory_get_peak_usage(true) / 1024 / 1024)."M";

$endTime = time();

echo "<div>解析完后,当前的时间为:".date("Y-m-d H:i:s")."   

总共消耗的时间为:".(($endTime - $startTime))."秒</div>";

var_dump($dataArr);

$dataArr = NULL;}

[Recommended] Related Articles

phpexcel how to use? phpexcel most common method summary

Super practical PHPExcel [import] [export] Implementation summary

Details of sample code read Excel time PHPExcel

How PHP to read large excel file data method

[Related video courses recommended]

PHP manipulate Excel Video Tutorials

The above is how to read the contents of files with PHP excel for detailed contents of the cell data, please pay attention to more php Chinese net other related articles!

Guess you like

Origin www.cnblogs.com/2019gdiceboy/p/11389850.html