Original works, reprinting is allowed. When reprinting, please be sure to indicate the article original source , author information and this statement in the form of a hyperlink. Otherwise held liable. http://ustb80.blog.51cto.com/6139482/1066505
In my work, I often encounter the problem of importing part of the xlsx file into the database. Usually we use PHPExcel to read.
We can easily read an excel table into a php array through the following method, and then we can do whatever we want:
If the article ends here, it will not be of much value.
Unfortunate situations always exist. When data.xlsx has tens of thousands of rows, each row has many columns, each column has a long string, and some have color and other effects, use the above What often happens with methods is that they run out of memory.
Well, we still have ini_set to increase the memory, and we can also use set_time_limit to set a longer timeout, as follows:
But it is very responsible to say that these are not the ultimate solution.
I once tried setting the memory to 2G and the timeout to 90 seconds, but I still couldn’t read a colorful table with 4,000 rows. The reason lies in the toArray method, which saves all the processing results into an array. This method is very convenient when processing simple tables, but it is really useless when processing large tables.
Our solution is as follows:
The above method is considered a more complicated situation. If you just want to read out all the cells, just use the following method:
We can The above print_r place is changed to combine the sql statement and write it to the file, and then use mysql to import it. Of course, you can also directly connect to the database to insert records into the table. This is optional.
Using this method, tens of thousands of rows of records can be easily imported into the table. I hope it will be helpful to everyone.
This article comes from the "Fanxing's Technology Blog" blog, please be sure to keep this source http://ustb80.blog.51cto.com/6139482/1066505
The above introduces how to use PHPExcel to read very large excel files, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.