how to solve NotOfficeXmlFileException

Viewed 913

I have an API for uploading excel file to a server and read it, so my code below

public ReturnSTH funcExample(@RequestParam("file") MultipartFile file) {
    Sheet sheet = null;
    try {
        InputStream in = file.getInputStream();
        Workbook workbook = new XSSFWorkbook(in);
        sheet = workbook.getSheetAt(0);
    } catch (IOException e) {
        // do something
    }

then I have to test the API using JUnit as below

@Test
public void test() {
    MockMultipartFile fakeFile = new MockMultipartFile("file", "bank.xlsx", MediaType.TEXT_PLAIN_VALUE, "file data".getBytes());
    ReturnSTH response = funcExample(fakeFile);
}

I got the error like below

org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open XML) file

on the line Workbook workbook = new XSSFWorkbook(in);

I don't know how to fix this issue.

0 Answers
Related