The previous blog post has given a brief summary of the excel file exported by PHPExcel. Now I will make the following summary of how to read excel. (If the amount of data is not very large, you can use the web to read it directly using this method. If the amount of data is very large, it is recommended that the web only performs the upload function, and the reading and processing should be left in the background. PHPExcel is still relatively time-consuming. , memory.)
Example code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
What needs to be explained here is the "rich text conversion string" in the above comment.
When PHPExcel reads an EXCEl file, if the content in the cell has two fonts, it will read a rich text object:
For example: there is content in the cell: "Test 1", the first half of which is " The font of "Test" is Song Dynasty, and the font of "1" in the second half is Calibri. At this time, the value of the cell is obtained through
$cell = $sheet->getCell($addr)->getValue();
. And print:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
You can see that the text content of the cell cannot be read directly for such a cell. (Note: The rich text here is my own translation, I don’t know if it is correct).
In addition, the functions for reading cells are:
//Columns start from 0, rows start from 1
$currentSheet ->getCellByColumnAndRow($colIndex,$rowIndex)->getValue();