Using Phpexcel to read Excel 2007 or Excel2003 files, you need a friend, you can refer to the next.
Knowledge points involved:
PHP to iterate through Excel files
PHP converts characters into decimal numbers by ASCII encoding
PHP reads the Excel date format and displays the conversion
PHP code Conversion of Chinese characters garbled
<?PHPrequire_once' Phpexcel.php '; /** Format conversions for dates in Excel*/ functionGetData ($val){ $JD=Gregoriantojd(1, 1, 1970); $gregorian=Jdtogregorian($JD+intval($val)-25569); return $gregorian;/** display format is "month/day/year"*/ } $filePath= ' test.xlsx '; $PHPExcel=NewPhpexcel ();/** Read Excel by default with excel2007, if the format is not correct, then use the previous version to read*/ $PHPReader=Newphpexcel_reader_excel2007 ();if(!$PHPReader->canread ($filePath)){ $PHPReader=NewPhpexcel_reader_excel5 ();if(!$PHPReader->canread ($filePath)){ Echo' No Excel '; return ; } } $PHPExcel=$PHPReader->load ($filePath); /** Read the first worksheet in an Excel file*/ $currentSheet=$PHPExcel->getsheet (0); /** Get the maximum number of columns*/ $allColumn=$currentSheet-Gethighestcolumn ();/** Get a total number of lines*/ $allRow=$currentSheet-Gethighestrow ();/** Start output from the second line because the first behavior column name in the Excel table*/ for($currentRow= 2;$currentRow<=$allRow;$currentRow++){ /** Start output from column a*/ for($currentColumn= ' A ';$currentColumn<=$allColumn;$currentColumn++){ $val=$currentSheet->getcellbycolumnandrow (Ord($currentColumn)-65,$currentRow)->getvalue ();/**ord () converts a character to a decimal number*/ if($currentColumn= = ' A ') { EchoGetData ($val)." \ t "; }Else{ //echo $val;/** If the output character is garbled, the output must be encoded with the ICONV function to convert the GB2312 encoding to UTF-8 encoded output as follows*/ Echo Iconv(' Utf-8 ', ' gb2312 ',$val)." \ t "; } } Echo"</br>"; } Echo"\ n"; ?>
(Practical article) Phpexcel reading the implementation code of an Excel file