가져 오기 패키지는 여전히 그것의 간단한 포인트입니다 그래서, 그들은 항상 읽을 수없는 오류가있을 것입니다 스트림을 내보내는 이유를 알고하지 않습니다, 끈기, 포이 처리하지 않으려는 자신의있을 것입니다 :
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
도구 코드 :
public class FileUtil {
public static void download(String filename, HttpServletResponse res) {
String filePath = "./template/" + filename;
try (OutputStream os = res.getOutputStream(); InputStream bis = new BufferedInputStream(new ClassPathResource(filePath).getInputStream())){
// 设置信息给客户端不解析
String type = new MimetypesFileTypeMap().getContentType(filename);
// 设置content-type,即告诉客户端所发送的数据属于什么类型
res.setContentType(type);
// 设置编码
String name = URLEncoder.encode(filename, "UTF-8");
// 设置扩展头,当Content-Type 的类型为要下载的类型时 , 这个信息头会告诉浏览器这个文件的名字和类型。
res.setHeader("Content-Disposition", "attachment;filename=" + name);
XSSFWorkbook workbook = new XSSFWorkbook(bis);
workbook.write(os);
}catch (Exception e){
e.printStackTrace();
}
}
}
문구에 초점 : XSSFWorkbook는 통합 문서 = 새로운 XSSFWorkbook (비스)
파일의 위치 :