Export Displayed or Dynamic Html Table to excel

Hello , I have a HTML Table Generating from PHP Code like echo "<table>" etc.
The <td> content is dynamically generated and I want that table to export to excel. I tried using some jQuery but its not working properly.

You could try outputting it to a CSV of some other format Excel imports.

I searched many of them but they don’t export dynamic data

You would need to write the PHP code to export the CSV file.

Can you give an example code? Thanks!

You can write to a file in php using the fwrite function. Explained here.

If the content of the table is loaded with JavaScript you’re not going to be able to do this via crawling the HTML of the page. You will need an alternative method that is considerably more complex. Is there any reason why you can’t just fetch the data from the database and avoid crawling a page altogether.

From where and by what means?

from temporary tables which are created during script execution

The content comes from temporary tables created during php script execution. Its not stored anywhere.

I imagine that since it’s a PHP script that is writing the table, it could write the CSV file at the same time.

1 Like

It could but I want it to do it when the user wants i.e on button click and it gets downloaded to the users pc

The file could be written at the same time the table renders as the page loads, then the page could have a download link to it for the user.

1 Like

ninja’d by @SamA74

btw I tried a jquery export but the excel file is getting the html tags into it

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.