How to remove blank lines between sheets using POI?

I want to remove an empty row from an Excel worksheet using a POI.

We have a method like shiftRow() or removeRow() , but do not use it in this case. Please help me do this.

+4
source share
3 answers

Please try to execute part of the code. This also works for me when there are more than a few consecutive blank lines.

  for(int i = 0; i < sheet.getLastRowNum(); i++){ if(sheet.getRow(i)==null){ isRowEmpty=true; sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1); i--; continue; } for(int j =0; j<sheet.getRow(i).getLastCellNum();j++){ if(sheet.getRow(i).getCell(j).toString().trim().equals("")){ isRowEmpty=true; }else { isRowEmpty=false; break; } } if(isRowEmpty==true){ sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1); i--; } } 
+4
source

Although not verified, try the following:

 HSSFSheet sheet = workBook.getSheetAt(0); HSSFRow row = sheet.getRow(0); sheet.removeRow(row); 
0
source

This is a way to break cell reads when they delete rows taken as non-empty rows

 while(cellsIterator.hasNext()) { Cell currentCell = cellsIterator.next(); if(currentCell.getCellType() == Cell.CELL_TYPE_BLANK) { this.currentArraySheet.put("Headers",this.currentArraySheetHeaders); this.currentArraySheet.put("Rows",this.currentArraySheetRows); return; } if (currentCell.getCellTypeEnum() == CellType.STRING) { System.out.print(currentCell.getStringCellValue() + " | "); } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) { System.out.print(currentCell.getNumericCellValue() + "| "); } else if (currentCell.getCellTypeEnum() == CellType.BOOLEAN) { System.out.println(currentCell.getBooleanCellValue() + " | "); } } 
0
source

Source: https://habr.com/ru/post/1433712/


All Articles