Read Excel file, only read column A
function Import_excel ($filePath) {
$txt =array ();
$PHPReader = new phpexcel_reader_excel2007 ();
if (! $PHPReader->canread ($filePath)) {
$PHPReader = new Phpexcel_reader_excel5 ();
if (! $PHPReader->canread ($filePath)) {
Echo ' no Excel ';
return;
}
}
Create an Excel object where you can read the file from an Excel object, or write it to a file
$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 ();
echo "Allcolumn:". $allColumn. "
";
echo "Allrow:". $allRow. "
";
Iterates through the contents of each cell. Note that the row starts at 1 and the column starts from a
for ($rowIndex =1; $rowIndex <= $allRow; $rowIndex + +) {
for ($colIndex = ' A '; $colIndex <= $allColumn; $colIndex + +) {
echo $colIndex. ",";
$addr = $colIndex. $rowIndex;
$cell = $currentSheet->getcell ($addr)->getvalue ();
$txt [$rowIndex][]= $cell;
Echo $cell, ",";
}
echo "
";
}
return $txt;
}
Can only read the contents of column A, the following are not read, the examples on the Internet are like this
Is it for ($colIndex = ' a '; $colIndex <= $allColumn; $colIndex + +) to transcode A?
------to solve the idea----------------------
Please do not mislead, landlord's code and no big problem
for ($i = ' A '; $i! = ' AA '; $i + +) echo $i;
Abcdefghijklmnopqrstuvwxyz
References: For
($colIndex = ' A '; $colIndex <= $allColumn; $colIndex + +) {
$colIndex = ' A ';
$colIndex + +
A is a character, and the Execute + + will only be displayed as 1.
So every time it's 1.
Change to
for ($colIndex =0; $colIndex <= $allColumn; $colIndex + +) {
Try
------to solve the idea----------------------
References:
please do not mislead, landlord's code and no big problem
for ($i = ' A '; $i! = ' AA '; $i + +) echo $i;
Abcdefghijklmnopqrstuvwxyz
Quote: References:
for ($colIndex = ' A '; $colIndex <= $allColumn; $colIndex + +) {
$colIndex = ' A ';
$colIndex + +
A is a character, and the Execute + + will only be displayed as 1.
So every time it's 1.
Change to
for ($colIndex =0; $colIndex <= $allColumn; $colIndex + +) {
Try
Understand, if this problem is not here.