search
HomeBackend DevelopmentPHP Tutorialphp读取excel资料-reader.php excel操作类使用

php读取excel文件-reader.php excel操作类使用

?一、?概述

PHP-ExcelReader?是一个读取?Excel xsl?文件内容的一个?PHP?类。

它的下载网址:?http://sourceforge.net/projects/phpexcelreader/

本博客下载地址:phpExcelReader.zip

测试用Excel文件:测试.xls

文件名:?phpExcelReader.zip

包含两个必需文件:?oleread.inc?、?reader.php?。其它文件是一个应用例子?,?自述文件等

?

二、?文件使用

首先?,?包含?reader?类文件:?require_once " reader.php";

新建一个实例:?$xl_reader= new Spreadsheet_Excel_Reader ( );

设定编码信息: $xl_reader->setOutputEncoding('utf-8');//不设定可能会是乱码 要和网页显示编码一致

读取?Excel?文件信息:?$xl_reader->read("filename.xls");

?

它将导出?Excel?文件中所有可以识别的数据存储在一个对象中。数据存储在?2?个数组中,目前没有提供方法?/?函数访问这些数据?.?可以像下面这样简单的使用数组名。

?

sheets?数组包含了读取入对象的大量数据。它将导出?Excel?文件中所有可以识别的数据存储在一个?2?维数组中?$xl_reader->sheets[x][y]?。?x?为文档中的表序号,?y?是以下的某个参数?:

①??????? numRows -- int --?表的行数

例如:?$rows = $xl_reader->sheets[0]['numRows']

②??????? numCols -- int --?表的列数

例如:?$cols = $xl_reader->sheets[0]['numCols']

③??????? cells -- array --?表的实际内容。是一个?[row][column]?格式的?2?维数组

??例如:?$cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] //?行?2,?列?4?中的数据

④??????? cellsInfo -- array --?表格中不同数据类型的信息。每个都包含了表格的原始数据和类型。这个数组包含?2?部分:?raw --?表格原始数据;?type --?数据类型。

注:只显示非文本数据信息。

例如:?$cell_info = $xl_reader[0]['cellsInfo'][2][4]

$cell_info['raw'] is the raw data from the cell

$cell_info['type'] is the data type

?

$xl_reader->sheets?数组示例:

Array(    [0] => Array        (            [maxrow] => 0            [maxcol] => 0            [numRows] => 5            [numCols] => 3            [cells] => Array                (                    [1] => Array                        (                            [1] => 网站名称                            [2] => 网址                            [3] => 类型                        )                    [2] => Array                        (                            [1] => 百度                            [2] => http://www.baidu.com                            [3] => 搜索引擎                        )                    [3] => Array                        (                            [1] => 谷歌                            [2] => http://www.google.com.hk                            [3] => 搜索引擎                        )                    [4] => Array                        (                            [1] => 400电话                            [2] => http://www.my400800.cn                            [3] => 企业网站                        )                    [5] => Array                        (                            [1] => 新浪                            [2] => http://www.sina.com.cn                            [3] => 门户网站                        )                )        )    [1] => Array        (            [maxrow] => 0            [maxcol] => 0            [numRows] => 0            [numCols] => 0        )    [2] => Array        (            [maxrow] => 0            [maxcol] => 0            [numRows] => 0            [numCols] => 0        ))

?

boundsheets?数组包含了对象的其它信息,数组按?workbook?索引。?第二个索引为名称:?$xl_reader->boundsheets[i]['name']?返回第?i?个表的表名

例如:?$sheetname = $xl_reader->boundsheets[0]['name']; // name of the first sheet

?

$xl_reader-> boundsheets?数组示例:

Array(    [0] => Array        (            [name] => Sheet1            [offset] => 2148        )    [1] => Array        (            [name] => Sheet2            [offset] => 3484        )    [2] => Array        (            [name] => Sheet3            [offset] => 3760        ))

?

PHP-ExcelReader?只能支持?BIFF7 ,BIFF8?格式的文件。包括?Excel95?到?Excel2003.?但是不包含?Excel5.0?及之前的版本?.?实际上?Excel XP?和?Excel 2003?使用的?BIFF8X?是?BIFF8?格式的一个扩展?.?所有添加的特性可能不被?PHP-ExcelReader.?锁支持。否则它只能以?Excel XP/2003?文件运行。

Statement
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
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor