javascript 将 html 表导出到 ms word
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17917051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
exporting html tables to ms word
提问by John Doe
I have a html table in this format:
我有一个这种格式的 html 表:
<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
当用户单击“下载”按钮时,我需要以 ms word 格式导出/下载此表。请帮助我使用代码来实现这一点。提前致谢
回答by swsindonesia
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
这将强制您的用户将所有回声下载到 ms-word 文档中
回答by bayuforest
try this: http://phpword.codeplex.com/
试试这个:http: //phpword.codeplex.com/
Its work. I'm using it too
这是工作。我也在用
回答by Hassan
Here's a library called phpdocxthat can be used from PHP. There's even a page about converting HTML to docx. The code there looks something like this:
这是一个可以从 PHP 使用的名为phpdocx的库。甚至还有一个关于将 HTML 转换为 docx 的页面。那里的代码看起来像这样:
require_once 'pathToPHPDocX/classes/CreateDocx.inc';
$docx = new CreateDocx();
$html='<p>some html</p>';
$docx->embedHTML($html);
$docx->createDocx('simpleHTML');
回答by hadi moazen
header("Content-Type: application/vnd.msword");
header("content-disposition: attachment;filename=sampleword.doc");