您好,登錄后才能下訂單哦!
java解決導出Excel時文件名亂碼的方法示例:
String agent = request.getHeader("USER-AGENT").toLowerCase(); response.setContentType("application/vnd.ms-excel"); String fileName = "文件名"; String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8"); if (agent.contains("firefox")) { response.setCharacterEncoding("utf-8"); response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1") + ".xls" ); } else { response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls"); }
encode() 方法以指定的編碼格式編碼字符串。
擴展:
Java POI導出Word文檔代碼
pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.14</version>
</dependency>
Controller:
@Transactional(propagation=Propagation.SUPPORTS)
@ResponseBody
@RequestMapping("/ExportInterpretationSignsWord")
public ResponseEntity<byte[]> ExportInterpretationSignsWord(@RequestParam String token,HttpServletRequest request,
HttpServletResponse response,
@RequestParam int id) throws IOException{
response.setContentType("text/html;charset=UTF-8");
response.setHeader("Content-type", "application/json;charset=UTF-8");
if(RedisPool.checkToken(token)==false) {
return null;
}
ResponseEntity<byte[]> temp=buildService.ExportInterpretationSignsWordById(id);
return temp;
}
以上就是java導出excel時出現文件名亂碼解決方法的詳細內容,更多請關注億速云其它相關文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。