Create Excel reports with phpSpretadsheet (update) |
12/14/2023 6:29:27 AM |
PHPRunner Tips and Tricks | |
![]()
I have updated this article and example to bring it into line with the latest versions of the phpSpreadsheet PHP library . This version requires PHP 8.X and I have added the “dompdf/dompdf” extension, to create PDFs, and the “mitoteam/jpgraph” library, for PDF graphics. I have tried converting the example reports to PDF and the result, from my point of view, is still very bad. Also, I have generalized data access so that it is not dependent on MySQL. Now it would work for any database. I have made the report on Municipalities with division and header by Province following the proposed method of inserting lines to “drag” the styles of the rows, which I have called “slow” and the so-called “fast” method I have used the copying method. styles, without making line insertions. When inserting lines, in addition to copying the styles, it reviews the entire sheet to recalculate the formulas and hence the delay that has an exponential progression of the time required as the number of records increases. For 8,122 records, the improvement is at least 10 to 1. DEMO: https://fhumanes.com/reports/ If you are interested in this topic, continue reading the article at this link . |
|
C
|
cristi 12/14/2023 |
Great job as always from you.
A big minus for it: it is not supporting those fancy styles that phpdpreadsheet does. I also found this - FastExcelWriter (https://github.com/aVadim483/fast-excel-writer) and verifying the claims by the author I can say that it is faster than phpspreadshet but I would still not recommend it for large ammounts of data: 7-9 times faster |
![]() |
Admin 12/14/2023 |
Fernando and cristi, thank you for chiming in. It is good to know that there are faster alterbative available. We have choosen phpSpreadSheet because it seems to be the most widely used solution and the most comprehensive, functionality wise. It is good to know that if we need to implement some new feature, phpSpreadSheet is likely to support it. However, functionality often comes with the price, which is performance in this case. I must add one thing. If you intend to export huge amounts of data, CSV is probably the best option. Excel is better for presentation purposes, not for a huge datasets transfer. After all, web applications aim to solve the exact issue that Excel creates, you do not want to pass bunch of data around. |
![]() |
fhumanes author 12/15/2023 |
Hi @cristi. In the first version of the article, my example relied on the use of insertion of new "Rows" and problems were observed when the number of rows was large and made rows insertion operations into the spreadsheet. Except for this case, the performance of the proposed solution was very good. I studied the problem and I have seen that instead of using row insertion to drag the styles of that row, if the styles are copied, the time effect disappears and the result is very good. In the example, 192 pages take 13 seconds on a normal PC. This solution is functionally very good and you just have to take into account this problem in large spreadsheets. Between that I write in Spanish and translate from English to Spanish, I must express myself badly, because what I wanted to express in this article has not been understood. Thanks for your words and for the references you have shared. Greetings, |
![]() |
fhumanes author 12/15/2023 |
Hi @Sergey. How I have explained to @cristi, if you have not understood what I wanted to explain in the article it is because I translate very badly to English or my text I was not sufficiently explained. What I wanted to indicate is:
I hope now what I wanted to express is clearer and if not, I will try again. Regarding the CSV format, I can agree that it is a fast information output, but I would never consider it a user report of an application. Greetings, |
C
|
cristi 12/16/2023 |
@admin - CSV format was created mainly for machines - reading csv is perfectly possible but it is not a pleasant experience for humans... |
![]() |
fhumanes author 12/18/2023 |
Thank you very much @cristi |