I am converting a multipart file into an input stream and then further into an Excel workbook. But when I do it new line characters inside the cell are not getting converted properly and the cell value is different from what I intend.
I upload an excel file, that converts it into a multipart-file. I reconvert it into excel by first converting it into an input stream I am not able to do it properly as string values containing newline character in the cell are not getting processed correctly. How do avoid this mistake?
public String bulkUploadHtml(MultipartFile multipartFile, String email) {
String message = "*File is being processed. Upload status will be sent via email.";
if (StringUtils.isEmpty(multipartFile.getOriginalFilename())) {
message = "Invalid file uploaded. Please try again.";
LOG.error(message);
return message;
}
try{
InputStream inputStream = multipartFile.getInputStream();
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while(rowIterator.hasNext()){
Row row = rowIterator.next();
Cell cell = row.getCell(0);
String supc = cell.getStringCellValue();
cell = row.getCell(1);
String html = cell.getStringCellValue();
LOG.info("SUPC + " + supc);
LOG.info("HTML incoming + " + html);
}
}catch (Exception e){
LOG.info("ERROR parsing excel html bulk upload file " + e.toString());
}
return null;
}
For example, if cell[0] has value "123\n456" only 123 comes when I access the value as cell.get(0).