导出word或者excel文件,请求的书写的方式

下载word:

 

//把文件下载成字节数组
byteProductWord = productService.productMomGoodsWord(productId,request);

String fileName = URLEncoder.encode((productName==null?"无产品名称":productName)+".docx", StandardCharsets.UTF_8.toString());
response.setContentType("application/msword;charset=UTF-8"); // 下载文版类型
response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
outputStream.write(byteProductWord);

 

下载excel的标准格式:

response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition","attachment;filename*=UTF-8''" + URLEncoder.encode(filename, "UTF-8"));
把表格写到表格中:
hssfWorkbook.write(outputStream);
outputStream.flush();
outputStream.close();
return outputStream;

 

 

 

你可能感兴趣的:(导出word或者excel文件,请求的书写的方式)