java中除了使用常规的库来实现到处word,excel外,可以在jsp里配置实现导出效果,实际上效果是一致的,这里记录下相关的配置。
1、设置response
response.setContentType("application/vnd.ms-word; charset=UTF-8");
response.setHeader("Pragma","No-Cache");
response.setHeader("Cache-Control","No-Cache");
response.setHeader("Content-disposition","attachment; filename="+URLEncoder.encode(nc+"("+bh+")", "UTF-8")+".doc");
2、html指定word
<html xmlns:w='urn:schemas-microsoft-com:office:word' >
3、head里添加配置文件
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:DoNotOptimizeForBrowser/>
<w:Compatibility>
<w:DontGrowAutofit/>
</w:Compatibility>
</w:WordDocument>
</xml>
4、导出
$("table").attr("border",'0');
window.print();
版权属于:Jolly
本文链接:https://totoro.site/index.php/archives/7/
关于转载:原创文章,禁止转载