python - How to solve the problem when the browser is half stuck when exporting excel with more than 10,000 items?
習慣沉默
習慣沉默 2017-06-14 10:49:44
0
13
2023

Business requirements sometimes require tens of thousands of items to be exported.
Can I use python to process it?? It’s too stuck.
What if I use python to process it?

習慣沉默
習慣沉默

reply all(13)
伊谢尔伦

More than 10,000 items are not a lot. You can use the third-party library PHPExcel. Or directly export csv, function: fputcsv .

代言

If you want to export, just export it directly to CVS mode.

phpcn_u1582

You don’t need to export it all at once. Export in batches

三叔

Time-consuming server tasks like this should not be designed as Browser->Sync->Server;
should be in the form of asynchronous tasks:

  1. Browser: I want an Excel, please generate it for me first

  2. Server: OK, the mission has started

  3. Browser: Let me refresh it and see (you can use a long connection instead), it seems to be completed. Give me the URL (URL can be reflected in the task, no need to obtain it again), I want to download it

  4. Server: http://domain.com/test.xlsx

  5. Browser: Start download

学习ing

Isn’t it enough to have more than 10,000 entries? How big is the file?

三叔

You can make the generation segmented... write 1000 items in 1000 items.
In addition, if php times out, you can change set_time_limit()

我想大声告诉你

Asynchronous, all export operations should be made asynchronous

淡淡烟草味

Written in paging, for example, refresh once every 1000 items

学习ing

Use the script to run, php -f export.php

为情所困

Use asynchronous or multi-process, the browser submits the task, prompting that the task is being processed, the background multi-process script slowly processes it, and when it is completed, it pushes a message to the browser to prompt the user that the export operation has been completed and can be downloaded.
Browser push message: http://www.workerman.net/web-...
Multi-process framework: http://doc3.workerman.net/ins...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template