Knowledge points:
Php reads excel files cyclically
Php encodes the characters in ascii format and converts the characters into decimal numbers.
Php reads the excel Date Format and converts it to display
Php encodes Chinese characters with garbled characters
Copy codeThe Code is as follows:
<? Php
Require_once 'phpexcel. php ';
/** Convert the date format in excel */
Function GetData ($ val ){
$ Jd = GregorianToJD (1, 1, 1970 );
$ Gregorian = JDToGregorian ($ jd + intval ($ val)-25569 );
Return $ gregorian;/** the display format is "month/day/year "*/
}
$ FilePath = 'test.xlsx ';
$ PHPExcel = new PHPExcel ();
/** Excel is read using excel2007 by default. If the format is incorrect, it will be read using the previous version */
$ PHPReader = new PHPExcel_Reader_Excel2007 ();
If (! $ PHPReader-> canRead ($ filePath )){
$ PHPReader = new PHPExcel_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 );
/** Obtain the largest column number */
$ AllColumn = $ currentSheet-> getHighestColumn ();
/** Obtain the total number of rows */
$ AllRow = $ currentSheet-> getHighestRow ();
/** Output from the second row because the first row column name in the excel table */
For ($ currentRow = 2; $ currentRow <= $ allRow; $ currentRow ++ ){
/** Output from column */
For ($ currentColumn = 'a'; $ currentColumn <= $ allColumn; $ currentColumn ++ ){
$ Val = $ currentSheet-> getCellByColumnAndRow (ord ($ currentColumn)-65, $ currentRow)-> getValue ();/** ord () convert characters into decimal numbers */
If ($ currentColumn = 'A ')
{
Echo GetData ($ val). "\ t ";
} Else {
// Echo $ val;
/** If garbled characters are output, use the iconv function to convert the output content. Convert gb2312 encoding to UTF-8 encoding as follows */
Echo iconv ('utf-8', 'gb2312', $ val). "\ t ";
}
}
Echo "</br> ";
}
Echo "\ n ";
?>