Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add streaming mode for writing excel files #244

Closed
jontro opened this issue Oct 10, 2017 · 13 comments
Closed

Add streaming mode for writing excel files #244

jontro opened this issue Oct 10, 2017 · 13 comments

Comments

@jontro
Copy link

jontro commented Oct 10, 2017

Currently PhpSpreadsheet buffers the xlsx until it's written out to a stream which will be a problem if the generated dataset is very large.

Apache POI has a streaming implementation (https://poi.apache.org/spreadsheet/) where it solves this by restricting the operations if using it in a streaming mode.

  • Only a limited number of rows are accessible at a point in time.
  • Sheet.clone() is not supported.
  • Formula evaluation is not supported

Would it be possible to add something similar to PHPSpreadsheet?

@PowerKiKi PowerKiKi changed the title Feature request: Add streaming mode for writing excel files Add streaming mode for writing excel files Oct 10, 2017
@PowerKiKi
Copy link
Member

Do you mean create a spreadsheet from scratch, in-memory, and while you add new cells/rows, some "previous cells" are written down on disk and deleted from memory ? Keeping the memory usage very low at all time ?

@jontro
Copy link
Author

jontro commented Oct 11, 2017

I was thinking that you could open a file pointer to php://output right away so the contents will start being served immediately.
I.e.

$objWriter = PHPExcel_IOFactory::createWriter('php://output', 'Excel2007');
$objPHPExcel = new PHPExcel($objWriter);
while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $row++;
    $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $row, $result['column']);
}
...

For very large datasets php will run out of memory if it's kept in buffer all the time

@PowerKiKi
Copy link
Member

This would most likely be a huge undertaking and Mark's input might be needed. Would you be willing to work on that?

@jontro
Copy link
Author

jontro commented Oct 12, 2017

I would absolutely be willing to help but I think it would have to be coordinated with multiple people. I have no real experience with working with the xlxs implementation details. What do you think? If it's a huge implementation change I wonder if it's really worth it, depending on how many library users would think this is useful.

Especially since the mode would limit other aspects of the api

@PowerKiKi
Copy link
Member

I agree that having multiple person involved might be best. Unfortunately I won't have enough time for that myself. So if you can find others, or invest enough time by yourself, then go for it. Otherwise I guess we'll have to do without that feature.

@MarkBaker any opinion on the matter ?

@stale
Copy link

stale bot commented Dec 12, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Dec 12, 2017
@stale stale bot closed this as completed Dec 19, 2017
@glenndavey83
Copy link

I could really use this right about now :/

@felansu
Copy link

felansu commented May 4, 2018

I too my bro... 💃

@eselskas
Copy link

me too

@xkzl
Copy link

xkzl commented May 31, 2022

same :(

@ghost
Copy link

ghost commented Jun 1, 2022

:(

@ahmed-bhs
Copy link

Up!

@PowerKiKi
Copy link
Member

PowerKiKi commented Mar 13, 2023

To clarify, this is very unlikely to ever happen in PhpSpreadsheet. Spreadsheet content is not linear content, all kind of things depends on all kind of other things that must all exist at the same time to be able to write a complete, correct XLSX file. If you want to stream-write an XLSX file, you would lose really a lot of features. The API would need to be severely limited. So much so that it would not be reasonable to have a single codebase to support both use-cases.

If you need this kind of thing, you better look for an alternative product. Maybe something like https://github.com/mk-j/PHP_XLSXWriter

But if performance is your utmost concern, then https://www.php.net/manual/en/function.fputcsv.php is your best friend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants