PHP读取Excel文件类的具体应用

开发 后端
PHP读取Excel文件类的灵活掌握,可以为我们解决许多问题。对于新手来说,他们需要在不断的实际代码编写中积累经验。

我们在这篇文章中为大家详细介绍了一些有关PHP读取Excel文件类的相关用法,希望对正在学习PHP语言的新手们有些帮助,提高大家对PHP的理解程度。#t#

PHP读取Excel文件类代码示例:

  1. < ?php   
  2. require_once '../Excel/reader.php';   
  3. // ExcelFile($filename, $encoding);   
  4. $data = new Spreadsheet_Excel_Reader();   
  5. // Set output Encoding.指定中文码   
  6. $data->setOutputEncoding('gb2312');   
  7. /***   
  8. * if you want you can change 'iconv' 
    to mb_convert_encoding:   
  9. * $data->setUTFEncoder('mb');   
  10. *   
  11. **/   
  12. /***   
  13. * By default rows & cols indeces start with 1   
  14. * For change initial index use:   
  15. * $data->setRowColOffset(0);   
  16. *   
  17. **/   
  18. /***   
  19. * Some function for formatting output.   
  20. * $data->setDefaultFormat('%.2f');   
  21. * setDefaultFormat - set format for 
    columns with unknown formatting   
  22. *   
  23. * $data->setColumnFormat(4, '%.3f');   
  24. * setColumnFormat - set format for 
    column (apply only to number fields)   
  25. *   
  26. **/   
  27. // 指定读取的excel文件   
  28. $data->read('../uploads/jsxz01.xls');   
  29. /*   
  30. $data->sheets[0]['numRows'] - count rows   
  31. $data->sheets[0]['numCols'] - count columns   
  32. $data->sheets[0]['cells'][$i][$j] - 
    data from $i-row $j-column   
  33. $data->sheets[0]['cellsInfo'][$i][$j] - 
    extended info about cell   
  34. $data->sheets[0]['cellsInfo'][$i][$j]
    ['type'] = "date" | "number" | "unknown"   
  35. if 'type' == "unknown" - use 'raw' 
    value, because cell contain value with 
    format '0.00';   
  36. $data->sheets[0]['cellsInfo'][$i][$j]
    ['raw'] = value if cell without format   
  37. $data->sheets[0]['cellsInfo'][$i][$j]
    ['colspan']   
  38. $data->sheets[0]['cellsInfo'][$i][$j]
    ['rowspan']   
  39. */   
  40. error_reporting(E_ALL ^ E_NOTICE);   
  41. // 循环读取每一个单元值   
  42. for ($i = 1; $i <= $data->sheets[0]
    ['numRows']; $i++) {   
  43. for ($j = 1; $j <= $data->sheets[0]
    ['numCols']; $j++) {   
  44. echo "\"".$data->sheets[0]['cells']
    [$i][$j]."\",";   
  45. }   
  46. echo "<br>";   
  47. }   
  48. //print_r($data);   
  49. //print_r($data->formatRecords);   
  50. ?>  

以上就是PHP读取Excel文件类的全部用法,作为一个参考对象。

责任编辑:曹凯 来源: 网易博客
相关推荐

2009-11-24 15:01:59

PHP通用文件上传类

2009-11-30 16:08:32

PHP addslas

2009-12-03 17:18:15

PHP strtoti

2009-12-02 18:51:12

PHP分页类

2009-11-24 15:50:09

PHP上传类uploa

2009-11-30 11:24:49

PHP将EXCEL导入

2009-12-04 16:49:38

PHP导出Excel乱

2009-12-03 09:49:59

PHP分页导航函数

2009-12-04 17:31:32

PHP编码转换

2009-11-24 14:22:03

基于PHP的AJAX技

2009-12-04 15:52:46

PHP导入Excel文

2009-11-24 16:28:41

PHP5魔术函数

2009-11-24 13:26:17

2009-12-01 14:33:06

PHP生成html文件

2009-11-24 14:52:45

PHP动态多文件上传

2009-11-26 14:23:10

PHP正则模式修正符

2009-12-08 16:48:25

PHP类phpExce

2009-11-27 15:31:33

PHP类搜索定位目录树

2011-06-14 16:07:13

Qt QSettings类

2009-12-03 14:10:06

PHP压缩文件夹
点赞
收藏

51CTO技术栈公众号