문제를 해결하기 위해 자바 엑셀은 깨진 내 보낸 파일 열기를 읽을 수는 복원 할 수

가져 오기 패키지는 여전히 그것의 간단한 포인트입니다 그래서, 그들은 항상 읽을 수없는 오류가있을 것입니다 스트림을 내보내는 이유를 알고하지 않습니다, 끈기, 포이 처리하지 않으려는 자신의있을 것입니다 :

<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 (비스)

파일의 위치 :

게시 56 개 원래 기사 · 원 찬양 75 · 전망 280 000 +

추천

출처blog.csdn.net/seanxwq/article/details/104774543