0
点赞
收藏
分享

微信扫一扫

_史上最简单的word导出,HTML直接导出,无需后台代码


技术交流群:958923746,有学习视频,文档等。

一、这是jquery的插件导出word,适用于导出跟HTML上相同的业务,如果导出的word跟HTML上不一致,那么还得修改一些。

本次主要讲与界面HTML相同的导出格式。

GIT地址:​​https://github.com/eligrey/FileSaver.js/​​

JS代码:

//导入插件JS
<script src="/static/common/fileSaver.js" type="text/javascript"></script>
<script src="/static/common/jqword.js" type="text/javascript"></script>

function exportWord(){
$("#export_word").wordExport(“导出的word文件名,默认自带.doc”);
}

界面代码,简单的:

<div id="export_word"><!-- 选择要导出的文档内容 div里面 -->
<div class="box-body collapse in">
<table class="table table-striped table-bordered table-hover" style="word-break:break-all; width:100%; cellspacing:0;">
<tbody>
<tr>
<td class="text-bold text-right col-sm-2">国内手机</td>
<td id="yhydm">小米</td>
<td class="text-bold text-right col-sm-2">国外手机</td>
<td id="hydm">苹果</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- 结束 -->
<button type="button" class="btn btn-primary" onclick="exportWord()">导出word</button>

点击按钮即可导出,注意,如果是table表格的HTML,那么td跟tr中不可以有其他的标签,不可以存在input,span,div等。只可以是要导出的数据哦。切记。

效果图:

_史上最简单的word导出,HTML直接导出,无需后台代码_excel导出

举报

相关推荐

0 条评论