Forum


Replies: 1   Views: 51
Create table with data chunks

Posted by Teresa Alvarez  · 17-07-2025 - 21:45

Hi

I'm creating a report containing a table of approximately 6,400 records. Following the examples in the documentation, creating a report with approximately 840 pages takes a long time (19 minutes). Upon analysis, I find that the bottleneck is creating the $valuesTable array with all the values (6,400 rows) to add to the $docx->addTable() statement.

One solution is to use chunks, but if I want to create a single table, I have to use variables by reference (&$valuesTable), and this makes no difference. Another solution is to create a table for each chunk. Although this doesn't cause me any problems, each $docx->addTable() statement leaves a blank line, which is something I want to avoid.

Is there a solution to create the table with $docx->addTable() without having to create the $valuesTable array, or can $docx->addTable() process the array in chunks or remove the line after table?

I'm using phpdocx 15 and a little context: in my local environment I use 1GB of memory, and if I create a table for each chunk, the report is generated in approximately 3 minutes, the same 845 pages.