<? Php // PHPExcel need to download Official Website: http://www.codeplex.com/PHPExcelheader ("Content-Type: text/html; charset = UTF-8"); require_once '. /PHPExcel. php '; require_once '. /PHPExcel/IOFactory. php '; require_once '. /PHPExcel/Reader/Excel5.php ';/*** read the Excel table * @ param $ filePath Excel file path * @ param $ field the field to be saved in array ('id ', 'username', 'Password') * @ param $ column reads the array ('A', 'B', 'C') of the Excel column * @ examlpe $ filePath = '1.xls '; $ field = array ('I D', 'username', 'Password'); $ column = array ('A', 'B', 'C'); readExcel ($ filePath, $ field, $ column); */function readExcel ($ filePath, $ field, $ column) {$ objReader = PHPExcel_IOFactory: createReader ('excel5 '); // use excel2007 for 2007 format $ objPHPExcel = $ objReader-> load ($ filePath); // $ filename can be an uploaded file, or the specified file $ sheet = $ objPHPExcel-> getSheet (0); $ highestRow = $ sheet-> getHighestRow (); // get the total number of rows $ highestColumn = $ Sheet-> getHighestColumn (); // obtain the total number of columns for ($ j = 1; $ j <= $ highestRow; $ j ++) {$ colData = array (); $ count = count ($ column); for ($ I = 0; $ I <$ count; $ I ++) {$ colData [$ field [$ I] = $ objPHPExcel-> getActiveSheet ()-> getCell ($ column [$ I]. $ j)-> getValue (); // obtain the value of column A} $ excelData [] = $ colData;} return $ excelData ;} /*** export data into an excel table * @ param $ data: a two-dimensional array. The structure is like the array found from the database * @ param $ title: The first row title of excel, an array, if it is null, no title * @ param $ filename indicates the downloaded file name *@ Examlpe exportexcel ($ arr, array ('id', 'account', 'Password', 'nickname '), 'file name! '); */Function exportexcel ($ data = array (), $ title = array (), $ filename = 'report') {header ("Content-type: application/octet-stream "); header (" Accept-Ranges: bytes "); header (" Content-type: application/vnd. ms-excel "); header (" Content-Disposition: attachment; filename = ". $ filename. ". xls "); header (" Pragma: no-cache "); header (" Expires: 0 "); // export xls to start if (! Empty ($ title) {foreach ($ title as $ k => $ v) {$ title [$ k] = iconv ("UTF-8", "GB2312 ", $ v) ;}$ title = implode ("\ t", $ title); echo "$ title \ n" ;}if (! Empty ($ data) {foreach ($ data as $ key => $ val) {foreach ($ val as $ ck => $ cv) {$ data [$ key] [$ ck] = iconv ("UTF-8", "GB2312", $ cv );} $ data [$ key] = implode ("\ t", $ data [$ key]);} echo implode ("\ n", $ data) ;}}?>