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
Copy the Code code as follows:
Require_once ' phpexcel.php ';
/** format conversions for dates in Excel */
function GetData ($val) {
$JD = GREGORIANTOJD (1, 1, 1970);
$gregorian = Jdtogregorian ($jd +intval ($val)-25569);
return $gregorian;/** display format is "month/day/year" */
}
$filePath = ' test.xlsx ';
$PHPExcel = new Phpexcel ();
/** default to read Excel with excel2007, if the format is not correct, then use the previous version to read */
$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);
/** reading the first worksheet in an Excel file */
$currentSheet = $PHPExcel->getsheet (0);
/** get the largest column number */
$allColumn = $currentSheet->gethighestcolumn ();
How many lines does the/** get altogether? */
$allRow = $currentSheet->gethighestrow ();
/** starts the output from the second line because the first behavior in the Excel table is listed in the name */
for ($currentRow = 2; $currentRow <= $allRow; $currentRow + +) {
/** start output from column A */
for ($currentColumn = ' A '; $currentColumn <= $allColumn; $currentColumn + +) {
$val = $currentSheet->getcellbycolumnandrow (ord ($currentColumn)-up, $currentRow)->getvalue ();/**ord () Convert character to decimal number */
if ($currentColumn = = ' A ')
{
echo GetData ($val). " \ t ";
}else{
Echo $val;
/** if the output character is garbled, the output will need to be encoded with the ICONV function to convert, as follows GB2312 encoding to UTF-8 encoded output */
echo iconv (' Utf-8 ', ' gb2312 ', $val). " \ t ";
}
}
echo "
";
}
echo "\ n";
?>
The above describes the official download of the Excel 2007 free full version of the Phpexcel read the implementation code of the Excel file, including the official download of the Excel 2007 free full version of the content, I hope to be interested in PHP tutorial friends helpful.