您好,登錄后才能下訂單哦!
java解決導(dǎo)出Excel時(shí)文件名亂碼的方法示例:
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() 方法以指定的編碼格式編碼字符串。
擴(kuò)展:
Java POI導(dǎo)出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導(dǎo)出excel時(shí)出現(xiàn)文件名亂碼解決方法的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注億速云其它相關(guān)文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。