Click here to Skip to main content
15,849,829 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a project in django, in which I have a table in my html page :
   <br />
<table  class="table table-bordered border-success" ><br />
    <thead style="height: 500%;"><br />
        <tr><br />
            <th scope="col">Serail Number:</th><br />
            <th scope="col">Date</th><br />
            <th scope="col"><h1>Activities</h1></th><br />
            <th scope="col">Numbers/Hours</th><br />
            <th scope="col">Position of Interviewed Person</th><br />
            <th scope="col">Marks (out of 10)</th><br />
            <th scope="col"><h1>Comments</h1></th><br />
            <th scope="col">Attachments</th><br />
            <th scope="col">Refer</th><br />
        </tr><br />
    </thead><br />
    <tbody style="height: 500%;"><br />
        {% for interview in interviews %}<br />
        <tr><br />
            <td>{{ forloop.counter }}</td><br />
            <td>{{ }}</td><br />
            <td style="width: 30%;">{{ interview.activities }}</td><br />
            <td >{{ interview.no_of_Hours }}</td><br />
            <td>{{ interview.positon_of_interviewd_person }}</td><br />
            <td>{{ interview.marks }}</td><br />
            <td style="width: 100%;">{{ interview.comments }}</td><br />
            {%if interview.attachments%}<br />
            <td><a href="{{ interview.attachments.url }}">CV</a></td><br />
            {%else%}<br />
            <td>No Cv</td><br />
            {%endif%}<br />
            {%if interview.refer%}<br />
            <td>Yes</td><br />
            {%else%}<br />
            <td>No</td><br />
            {%endif%}<br />
<br />
        </tr><br />
        {% endfor %}<br />
    </tbody><br />
</table><br />

I want to give the user a button named "export to excel" and when he clicks it the table is converted into excel sheet (or csv sheet using pandas) and is downloaded at user`s side.

Thanks in advance!

What I have tried:

Updated 23-Jan-23 9:06am

1 solution

That's not the best approach. You should be taking the data you used to generate the HTML table and just generate the Excel or CSV file instead. Converting the HTML to Excel or CSV is unwise as the only data type you're going to get is a string, no matter what the data really is.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900