Home Backend Development PHP Tutorial php excel read excel drop-down menu how to do excel2013 official download excel2007

php excel read excel drop-down menu how to do excel2013 official download excel2007

Jul 29, 2016 am 08:49 AM
excel

Of course, you must first determine whether there is a file and the file type, and then save the file to a certain path

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

38

<span>/*</span><span>*

 * 读取excel数据

 * @author Red

 * @date

 * @param $filename 文件所在路径+文件名

 * @param string $encode

 * @param $file_type

 * @return array

 </span><span>*/</span><span>function</span> readExcel(<span>$filename</span>, <span>$encode</span> = 'utf-8', <span>$file_type</span><span>)

{

    </span><span>include</span> './plugins/excel/PHPExcel.php'<span>;

    </span><span>include</span> './plugins/excel/PHPExcel/Reader/Excel2007.php'<span>;

    </span><span>include</span> './plugins/excel/PHPExcel/Writer/Excel5.php'<span>;

    </span><span>include</span> './plugins/excel/PHPExcel/Writer/Excel2007.php'<span>;

 

    </span><span>if</span> (<span>$file_type</span> == 'xlsx'<span>) {

        </span><span>$objReader</span> = PHPExcel_IOFactory::createReader('Excel2007'<span>);

    } </span><span>else</span><span> {

        </span><span>$objReader</span> = PHPExcel_IOFactory::createReader('Excel5'<span>);

    }

 

    </span><span>$objReader</span>-&gt;setReadDataOnly(<span>true</span><span>);

 

    </span><span>$objPHPExcel</span>        = <span>$objReader</span>-&gt;load(<span>$filename</span><span>);

    </span><span>$objWorksheet</span>       = <span>$objPHPExcel</span>-&gt;<span>getActiveSheet();

    </span><span>$hightestrow</span>        = <span>$objWorksheet</span>-&gt;<span>getHighestRow();

    </span><span>$highestColumn</span>      = <span>$objWorksheet</span>-&gt;<span>getHighestColumn();

    </span><span>$highestColumnIndex</span> = PHPExcel_Cell::columnIndexFromString(<span>$highestColumn</span><span>);

    </span><span>$excelData</span>          = <span>array</span><span>();

   //从第二行开始

    </span><span>for</span> (<span>$row</span> = 2; <span>$row</span> &lt;= <span>$hightestrow</span>; <span>$row</span>++<span>) {

        </span><span>for</span> (<span>$col</span> = 0; <span>$col</span> &lt; <span>$highestColumnIndex</span>; <span>$col</span>++<span>) {

            </span><span>$excelData</span>[<span>$row</span>][] = (<span>string</span>)<span>$objWorksheet</span>-&gt;getCellByColumnAndRow(<span>$col</span>, <span>$row</span>)-&gt;<span>getValue();

        }

    }

 

    </span><span>return</span><span>$excelData</span><span>;

}</span>

Copy after login

The above introduces php excel reading, including excel content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to filter more than 3 keywords at the same time in excel How to filter more than 3 keywords at the same time in excel Mar 21, 2024 pm 03:16 PM

How to filter more than 3 keywords at the same time in excel

What should I do if the frame line disappears when printing in Excel? What should I do if the frame line disappears when printing in Excel? Mar 21, 2024 am 09:50 AM

What should I do if the frame line disappears when printing in Excel?

How to type subscript in excel How to type subscript in excel Mar 20, 2024 am 11:31 AM

How to type subscript in excel

How to change excel table compatibility mode to normal mode How to change excel table compatibility mode to normal mode Mar 20, 2024 pm 08:01 PM

How to change excel table compatibility mode to normal mode

How to set superscript in excel How to set superscript in excel Mar 20, 2024 pm 04:30 PM

How to set superscript in excel

Where to set excel reading mode Where to set excel reading mode Mar 21, 2024 am 08:40 AM

Where to set excel reading mode

How to use the iif function in excel How to use the iif function in excel Mar 20, 2024 pm 06:10 PM

How to use the iif function in excel

How to read excel data in html How to read excel data in html Mar 27, 2024 pm 05:11 PM

How to read excel data in html

See all articles