jsp实现导出word文档

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();
Last modification:November 25th, 2019 at 05:03 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment