It is recommended that the Web only upload function, read, processing or backstage bar. Phpexcel is still more time-consuming and memory-intensive.
Instance code:
error_reporting (0);
Require_once ' phpexcel_1.8.0/classes/phpexcel.php '; Modify the directory for yourself
Echo '
TEST phpexcel 1.8.0:read xlsx file
';
$filePath = "Cdkey.xlsx";
Create a Reader object
$PHPReader = new phpexcel_reader_excel2007 ();
if (! $PHPReader->canread ($filePath)) {
$PHPReader = new Phpexcel_reader_excel5 ();
if (! $PHPReader->canread ($filePath)) {
Echo ' file is not 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 ();
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 + +) {
$addr = $colIndex. $rowIndex;
$cell = $currentSheet->getcell ($addr)->getvalue ();
if ($cell instanceof Phpexcel_richtext)//Rich Text conversion string
$cell = $cell->__tostring ();
$arrExcel [$rowIndex] [$colIndex]= $cell;
}
}
Print_r ($arrExcel); exit;
Phpexcel_richtext Object (
[_richtextelements:private] = = Array
(
[0] = = phpexcel_richtext_textelement Object ([_text:private] = test)
[1] = = Phpexcel_richtext_run Object
(
[_font:private] = Phpexcel_style_font Object
(
[_name:private] = Calibri
[_size:private] = 11
[_bold:private] =
[_italic:private] =
[_superscript:private] =
[_subscript:private] =
[_underline:private] = None
[_strikethrough:private] =
[_color:private] = Phpexcel_style_color Object
(
[_argb:private] = FF000000
[_issupervisor:private] =
[_parent:private] =
[_parentpropertyname:private] =
)
[_parentpropertyname:private] =
[_issupervisor:private] =
[_parent:private] =
[ColorIndex] = 8
)
[_text:private] = 1
)
)
)
You can see that the text contents of the cell cannot be read directly to such a cell. (Note: The rich text here is my own translation, do not know to no).
In addition, the functions of reading cells are:
Column starting from 0, line starting from 1
$currentSheet->getcellbycolumnandrow ($colIndex, $rowIndex)->getvalue ();