javascript - 导出为EXCEL文件是重新查数据库还是从前端传数据?
ringa_lee
ringa_lee 2017-05-16 12:59:19
0
5
562

1.问题背景:前台页面用表格展示了数据,还要支持将数据导出为EXCEL文件。 查询数据库有时很慢(比如时间范围大[2年],sql语句执行时间差不多220s)
一般是导出的数据是重新查询数据库还是可以直接把前台得到的数据传给PHPExcel做处理?
感谢每一个回答者。
PS:sql语句优化尽力了(索引分区做了 多表有的表数据300w条),如果查询一周执行时间1.6s左右,查几年就得几分钟了。

ringa_lee
ringa_lee

ringa_lee

reply all(5)
Ty80
  1. html tables can be directly exported to xlsx;

  2. If 1 is not used, the acquired data will be cached before the front-end displays the data, and it can be sent back to the back-end when exporting without the need for another database operation;

  3. The premise of
  4. 2 is that the amount of data is within the acceptable range of front-end and back-end communication (for example, if it exceeds 50MB, it is too large), and the consumption of communication is sacrificed for the consumption of the database.

漂亮男人

In fact, js has a plug-in that can process excel, but don’t you still get the data in the frontend from the backend?

JS excel plug-ins, Baidu has a bunch of them, such as exceljs

Some mysql management software, such as navicat, can directly export the database to excel. You don’t have to use PHP to export. Although I can achieve everything with the best language in the world, you should also consider that other things can also be achieved

给我你的怀抱

Personally, I don’t support re-retrieving the data to the background. You can directly export the html to excel as shown above. Of course, you can process it in the background, but when you display the data in html, cache the data to the server. If you export excel, Read the data directly from the cache area and then output it to excel

刘奇

Generally, exporting data to EXCEL is a back-end operation. Here the user will select certain conditions to export the data. If the backend is time-consuming, it can be processed using asynchronous tasks.

小葫芦

Ask the question, I want to know if exporting data means exporting all data? Or can I choose a time range? If you are exporting everything, you can run a scheduled task in the background. Choose a time when the number of customers is small, such as going to the background at night to check all the data, and then just get it when exporting in the previous period. The scheduled task will also check the data regularly every day. Is it the latest

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!