exporting html tables to ms word

John Doe picture John Doe · Jul 29, 2013 · Viewed 12.6k times · Source

I have a html table in this format:

<table>
    <tr>
        <td></td>
        <td></td>
    </tr>
</table>

And I have a download button:

<input type="text" name="download" value="Download">

I need this table to be exported/downloaded in ms word format when user clicks on the Download button. Please help me with the codes to achieve this. Thanks in advance

Answer

swsindonesia picture swsindonesia · Jul 29, 2013

you may try the simple solution in setting your script header

 header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=YOUR_DOC_NAME.doc"); 

echo '<table>....';

that will force your user to download all the echo into ms-word document