Home > Backend Development > PHP Tutorial > php-PHP遍历excel文档并输出内容

php-PHP遍历excel文档并输出内容

WBOY
Release: 2016-06-02 11:34:44
Original
961 people have browsed it

php

header("Content-Type:text/html;charset=GB2312");
//这是下载脚本之家的excel_reader2.php包!百度下就有了!
require_once 'excel/excel_reader2.php';
$dir="wps/";//存放文件夹名
$handle=opendir($dir."."); //打开目录
$row=array();
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..") {
$row[]=$dir.$file; //输出文件名
//echo $file;
}
}
closedir($handle); //关闭打开的目录
//print_r($row);
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('GB2312'); //设置文本输出编码
//读取Excel文件
//问题从这里开始的,下面循环excel文档,但是输出内容总是不变!
//for($k=0;$k $data->read($row[0]);//这是包里面的函数,读取excel文档
//$data->sheets[0]['numRows']为Excel行数
for ($i = 1; $i sheets[0]['numRows']; $i++) {
}
//}
//$data->sheets[0]['numRows'] 是数组,要取的是$data->sheets[0]['numRows'][2]每行的内容(我的表里总共两行,所有表都一样!第一行为标题,要读取的是第二行的内容,所以为2),这里循环后,数组总不变,循环内容总是为第一个读取的内容!求高手能循环出所有文档中的内容!

<code>print_r($data->sheets[0]['cells'][2]);</code>
Copy after login

?>

Related labels:
php
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