Here is the Upload Controller that I am trying to read the .ods file with. I am reading each cell one by one through Java Workbook.
@RestController
public class UploadController {
@ApiOperation(value = "Upload mappings excel file", notes = "Uploads the excel file and stores on couchbase")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "File uploaded successfully"),
@ApiResponse(code = 500, message = "Internal server error"),
@ApiResponse(code = 400, message = "Bad request")
})
@RequestMapping(value = "/upload", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = "multipart/form-data")
public void uploadMappingsExcel(
@ApiParam(value = "file", example = "user.ods", required = true)
@RequestParam(value = "file", required = false) MultipartFile multipartFile) throws IOException{
Path path = null;
for(MultipartFile file : Collections.singleton(multipartFile)) {
path = Paths.get(file.getOriginalFilename());
Files.write(path,file.getBytes());
}
FileInputStream file = new FileInputStream(path.toString());
XSSFWorkbook workbook = new XSSFWorkbook(file);
Sheet sheet = workbook.getSheetAt(0);
DataFormatter dataFormatter = new DataFormatter();
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
String cellValue = dataFormatter.formatCellValue(cell);
System.out.print(cellValue + "\t");
}
System.out.println();
}
}
I am trying to upload the .ods file through Postman.