Home > Backend Development > PHP Tutorial > Example of phpexcel class library reading excel files

Example of phpexcel class library reading excel files

WBOY
Release: 2016-07-25 08:53:01
Original
1079 people have browsed it
  1. require_once('include/common.inc.php');
  2. require_once(rootpath . 'include/phpexcel/phpexcel/iofactory.php');
  3. $filepath = './file /xls/110713.xls';
  4. $filetype = phpexcel_iofactory::identify($filepath); //The file name automatically determines the file type
  5. $objreader = phpexcel_iofactory::createreader($filetype);
  6. $objphpexcel = $objreader- >load($filepath);
  7. $currentsheet = $objphpexcel->getsheet(0); //First workbook
  8. $allrow = $currentsheet->gethighestrow(); //Number of rows
  9. $output = array();
  10. $pretype = '';
  11. #// bbs.it-home.org
  12. $qh = $currentsheet->getcell('a4')->getvalue();
  13. //Follow The file format reads data in a loop starting from line 7
  14. for($currentrow = 7;$currentrow<=$allrow;$currentrow++){
  15. //Determine whether column b of each row is a valid serial number, if it is empty or less than The previous sequence number ends
  16. $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue();
  17. if(empty($xh))break;
  18. $tmptype = ( string)$currentsheet->getcell('c'.$currentrow)->getvalue(); //Event type
  19. if(!empty($tmptype))$pretype = $tmptype;
  20. $output[$xh] ['type'] = $pretype;
  21. $output[$xh]['master'] = $currentsheet->getcell('f'.$currentrow)->getvalue(); //Home team
  22. $output[ $xh]['guest'] = $currentsheet->getcell('h'.$currentrow)->getvalue(); //Guest team
  23. }
  24. //Loop down from the current row and take out the first rows that are not empty
  25. for( ; ; $currentrow++){
  26. $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue();
  27. if(!empty($ xh))break;
  28. }
  29. for( ; $currentrow <= $allrow; $currentrow++){
  30. $xh = (int)$currentsheet->getcell('b'.$currentrow)->getvalue( );
  31. if(empty($xh))break;
  32. $output[$xh]['rq'] = $currentsheet->getcell('i'.$currentrow)->getvalue();
  33. }
  34. header("content-type:text/html; charset=utf-8");
  35. echo 'Issue number:' . $qh . "nn";
  36. if(!empty($output)){
  37. printf( "%-5st%-15st%-40st%-40st%-5sn", 'serial number', 'event type', 'home team', 'away team', 'handicap value');
  38. foreach($output as $key => $row){
  39. $format = "%-5dt%-15st%-40st%-40st%-5sn";
  40. printf($format, $key, $row['type'], $row[' master'], $row['guest'], $row['rq']);
  41. }
  42. }
  43. ?>
Copy code


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