Thursday 15 January 2015

java - Unable to delete the Empty Rows Excel File using Apache POI -


I am trying to delete the blank lines inside my Excel file! My code is:

  Private zero changes (file f) {filef = F; HSSFWorkbook wb = null; HSSFSheet sheet = faucet; {FileInputStream = Try New FileInputStream (F); Wb = new HSSFWorkbook (is); Sheet = wb.getSheetAt (0); (Int i = 0; i & lt; sheet.getLastRowNum (); i ++) {if (sheet.getRow (i) == faucet) {sheet.shiftRows (i + 1, sheet.getLastRowNum), -1); I--; }} FileOutputStream fileOut = New FileOutputStream ("C: /juni1.xls"); Wb.write (fileOut); FileOut.close (); // Here I want to write a new update file without blank lines! } Hold (exception e) {System.out.print ("SERRO" + E); }}   

The code has no effect at all. Can any body tell me what the problem is, please help me, I have been trying to do this since the last 10 hours. thank you in advanced!

If any row is empty, there will be two cases.

  1. First of all, the row is between the other rows, but can not be created or created anytime in this case Sheet.tver (i) will be empty.
  2. And secondly, the row was made, it can not be used for cell or use, but now all its cells are empty. In this situation, sheet.Tetrev (i) will not be blank (You can see it using Sheet.getRow (i) .getLastCellNum () , it will always be available to you Rows are counted as equal.)

    In general the situation is second condition. Maybe in your case, it should be reason. For this you need to add additional status to check whether all the cells are empty.

     for  (int i = 0; i & lt; sheet.getLastRowNum (); i ++) {if (sheet.getrate (i) == faucet) {sheet.shiftrow ( I + 1, Sheet.Talesterone (), -1); I--; to continue; } (Int j = 0; j & lt; sheet.getRow (i) .getLastCellNum (); j ++) {if (sheet.getRow (i) .getCell (j) .toString () .tim () Equal ("")} {IsRowEmpty = true; } And {isRowEmpty = false; break; }} If (isRowEmpty == true) {sheet.shiftRows (i + 1, sheet.getLastRowNum), -1); I--; }}    

No comments:

Post a Comment