John Doe
John Doe

Reputation: 1

exporting html tables to ms word

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

Upvotes: -3

Views: 13568

Answers (4)

hadi moazen
hadi moazen

Reputation: 21

header("Content-Type: application/vnd.msword");
header("content-disposition: attachment;filename=sampleword.doc");

https://www.youtube.com/watch?v=Wg2eaqIEeYY

Upvotes: -1

bayuforest
bayuforest

Reputation: 118

try this: http://phpword.codeplex.com/

Its work. I'm using it too

Upvotes: 0

swsindonesia
swsindonesia

Reputation: 31

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

Upvotes: 3

user377628
user377628

Reputation:

Here's a library called phpdocx that can be used from PHP. There's even a page about converting HTML to docx. The code there looks something like this:

require_once 'pathToPHPDocX/classes/CreateDocx.inc';

$docx = new CreateDocx();

$html='<p>some html</p>';

$docx->embedHTML($html);

$docx->createDocx('simpleHTML');

Upvotes: 0

Related Questions