How to use excel phpspreadsheet cutting large files

background:

Use phpspreadsheet can easily parse excel file, but phpspreadsheet memory consumption is relatively large, I tried to parse text excel nearly 5M of memory usage will exceed the php default maximum memory 128M.

Of course, this method can be used to adjust the size of memory to solve, but a large amount of time in concurrency is more dangerous. Under the second method, we introduce today, to cut the use of excel file phpspreadsheet, this is a way to take time for space so the general requirements for timeliness of low demand can be used.

method:

First put a function phpspreadsheet official website provides readCell , we can use this feature to be cut.

First excel file read-ahead, mainly to obtain the number of rows of data in all worksheets and worksheet below, this method always return stage readCell are false, we only need to record readCell come worksheets and data rows.

Then is to get into the record analyzed to determine how much each part of the data line of the original excel the need to install, it should be noted that in order to avoid confusion content, do not talk about the contents of the table cut to two working together.

The final step is analyzing the data and using the cycle again readCell get every part of the data, attention must use every time a file is read disconnectWorksheets way to clean phpspreadsheet memory.

After my own tests found that the use of this method to resolve 5M excel file, an average of only 21M of memory can handle!

Guess you like

Origin www.cnblogs.com/lorrtt/p/11298225.html