Home > Backend Development > PHP Tutorial > Specific application of PHP reading Excel file class_PHP tutorial

Specific application of PHP reading Excel file class_PHP tutorial

WBOY
Release: 2016-07-15 13:33:12
Original
837 people have browsed it

In this article, we introduce in detail some code examples for

PHP to read Excel files:

  1. < ?php
  2. require_once '../Excel/reader.php';
  3. // ExcelFile($filename, $encoding);
  4. data
  5. = new Spreadsheet_Excel_Reader(); // Set output Encoding. Specify Chinese code
  6. $data-
  7. >setOutputEncoding('gb2312'); /***   
  8. * if you want you can change 'iconv'  to mb_convert_encoding:   
  9. * $data-
  10. >setUTFEncoder('mb');    *   
  11. **/ 🎜>
  12. /***   
  13. * By default rows & cols indeces start with 1   
  14. * For change initial index use:   
  15. * $data-
  16. >
  17. setRowColOffset(0);    *   
  18. **/
  19. // Specify the excel file to be read
  20. $data-
  21. >
  22. read('../uploads/jsxz01.xls');
  23. /*  $data-
  24. >

  25. sheets [0]['numRows'] - count rows
  26. $data-
  27. >sheets[0]['numCols'] - count columns $data-

  28. >
  29. sheets[0]['cells'][$i][$j] - data from $i-row $j-column
  30. $data -
  31. >
  32. sheets[0]['cellsInfo'][$i][$j] - extended info about cell $data-
  33. >
  34. sheets[0]['cellsInfo '][$i][$j]
  35. ['type'] = "date" | "number" | "unknown" if 'type' == "unknown " - use 'raw' value, because cell contains value with format '0.00'; $data-
  36. >sheets[0]['cellsInfo'][$i][$j] ['raw'] = value if cell without format
  37. $data-
  38. >sheets[0]['cellsInfo'][$i] [$j]['colspan']
  39. $data->sheets[0] ['cellsInfo'][$i][$j]
    ['rowspan']
  40. */
  41. error_reporting(E_ALL ^ E_NOTICE);
  42. // Loop to read each unit value
  43. for ($i = 1; $i <= $data->sheets[0]
    ['numRows'] ; $i++) {
  44. for ($j = 1 ; $j <= $data->sheets[0]
    ['numCols']; $j++) {
  45. echo "" ".$data->sheets[0]['cells']
    [$i][$j ]."",";
  46. }
  47. echo "<br>"; 🎜>//print_r($data); 🎜>formatRecords);
  48. ?> The above is all the usage of PHP to read Excel file class, as a reference object.
  49. http://www.bkjia.com/PHPjc/446091.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446091.html
  50. TechArticle
  51. In this article we introduce in detail some code examples for PHP to read Excel files: ?php require_once'../Excel/reader.php'; //ExcelFile($filename,$encoding); $ data...
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