Example of using the phpexcel class library to read an excel file
- Require_once ('include/common. inc. php ');
- Require_once (rootpath. 'include/phpexcel/iofactory. php ');
-
- $ Filepath = './file/xls/110713.xls ';
-
- $ Filetype = phpexcel_iofactory: identify ($ filepath); // the file name automatically determines the file type.
- $ Objreader = phpexcel_iofactory: createreader ($ filetype );
- $ Objphpexcel = $ objreader-> load ($ filepath );
-
- $ Currentsheet = $ objphpexcel-> getsheet (0); // The First Workbook
- $ Allrow = $ currentsheet-> gethighestrow (); // number of rows
- $ Output = array ();
- $ Pretype = '';
-
- # // Bbs.it-home.org
- $ Qh = $ currentsheet-> getcell ('A4 ')-> getvalue ();
- // Read data cyclically from 7th rows according to the file format
- For ($ currentrow = 7; $ currentrow <= $ allrow; $ currentrow ++ ){
- // Determine whether column B of each row is a valid sequence number. if it is null or smaller than the previous sequence number, it ends.
- $ Xh = (int) $ currentsheet-> getcell ('B'. $ currentrow)-> getvalue ();
- If (empty ($ xh) break;
-
- $ Tmptype = (string) $ currentsheet-> getcell ('C'. $ currentrow)-> getvalue (); // event type
- If (! Empty ($ tmptype) $ pretype = $ tmptype;
- $ Output [$ xh] ['type'] = $ pretype;
- $ Output [$ xh] ['master'] = $ currentsheet-> getcell ('F'. $ currentrow)-> getvalue (); // lead
- $ Output [$ xh] ['guest '] = $ currentsheet-> getcell ('H'. $ currentrow)-> getvalue (); // The target audience
- }
-
- // Starts from the current row and loops down to retrieve the first non-empty row
- For (; $ currentrow ++ ){
- $ Xh = (int) $ currentsheet-> getcell ('B'. $ currentrow)-> getvalue ();
- If (! Empty ($ xh) break;
- }
-
- For (; $ currentrow <= $ allrow; $ currentrow ++ ){
- $ Xh = (int) $ currentsheet-> getcell ('B'. $ currentrow)-> getvalue ();
- If (empty ($ xh) break;
-
- $ Output [$ xh] ['rq'] = $ currentsheet-> getcell ('I'. $ currentrow)-> getvalue ();
- }
- Header ("content-type: text/html; charset = utf-8 ");
-
- Echo 'period: '. $ qh. "\ n ";
- If (! Empty ($ output )){
- Printf ("%-5s \ t %-15s \ t %-40s \ t %-40s \ t %-5s \ n", 'sequence number ', 'event type ', 'team', 'TEAM', 'Let the ball value ');
- Foreach ($ output as $ key => $ row ){
- $ Format = "%-5d \ t %-15s \ t %-40s \ t %-40s \ t %-5s \ n ";
- Printf ($ format, $ key, $ row ['type'], $ row ['master'], $ row ['guest '], $ row ['rq']);
- }
- }
- ?>
|