PHP读取Excel表格内容,并且将其转换成数组
来源:互联网 发布:linux下php的好处 编辑:程序博客网 时间:2024/04/29 22:57
Excel表格:
<?php 2 /* 3 * 将excel转换为数组 by aibhsc 4 * */ 5 require('Excel/PHPExcel.php');//引入PHP EXCEL类 6 function format_excel2array($filePath='',$sheet=0){ 7 if(empty($filePath) or !file_exists($filePath)){die('file not exists');} 8 $PHPReader = new PHPExcel_Reader_Excel2007(); //建立reader对象 9 if(!$PHPReader->canRead($filePath)){10 $PHPReader = new PHPExcel_Reader_Excel5();11 if(!$PHPReader->canRead($filePath)){12 echo 'no Excel';13 return ;14 }15 }16 $PHPExcel = $PHPReader->load($filePath); //建立excel对象17 $currentSheet = $PHPExcel->getSheet($sheet); //**读取excel文件中的指定工作表*/18 $allColumn = $currentSheet->getHighestColumn(); //**取得最大的列号*/19 $allRow = $currentSheet->getHighestRow(); //**取得一共有多少行*/20 $data = array();21 for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){ //循环读取每个单元格的内容。注意行从1开始,列从A开始22 for($colIndex='A';$colIndex<=$allColumn;$colIndex++){23 $addr = $colIndex.$rowIndex;24 $cell = $currentSheet->getCell($addr)->getValue();25 if($cell instanceof PHPExcel_RichText){ //富文本转换字符串26 $cell = $cell->__toString();27 }28 $data[$rowIndex][$colIndex] = $cell;29 }30 }31 return $data;32 }33 34 print_r(format_excel2array('./1.xls'));
输出结果:
代码下载地址:
1
http:
//files.cnblogs.com/files/haveadream435/excel.rar
阅读全文
0 0
- PHP读取Excel表格内容,并且将其转换成数组
- php 读取txt文件中的内容,转换成数组
- php读取文件并且显示其内容
- PHP读取excel表格内容 PHP-ExcelReader
- php将xml文件转换成数组
- php将对象转换成数组
- PHP将XML转换成数组/对象
- 读取excel并将其转换为xml
- php 将json格式数据转换成数组
- PHP curl后json_decode无法将json转换成数组
- 怎样快速将excel表格内容转换到word中
- 将字符串转换成数组
- 将字符串转换成数组
- JAVA 从键盘读取字符并且转换成数字
- 读取excel表格的内容
- zend framework获取数据库中枚举类enum的数据并将其转换成数组
- 读取一个EXCEL的文件,然后将其转化成HTML的表格
- shell脚本----读取一个文本文件将内容按行保存成数组变量
- 安卓中的几种进程
- Caused by: com.ibm.websphere.ce.cm.ConnectionWaitTimeoutException: CWTE_NORMAL_J2CA1009
- android 圆角控件
- mybaits学习之基础理解
- 阿里10年分布式技术沉淀:阿里高可用体系核心缔造者、全链路压测创始人告诉你!
- PHP读取Excel表格内容,并且将其转换成数组
- ASP.NET Session的七点认识_知识库_博客园
- LeapMotion Demo3
- 哈希表的一些基本操作
- 在MFC中定义全局变量
- hibernate总结
- 解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOM
- Python3 除法小记
- 从《网安法》出发_给企业安全管理者的五条建议