Wednesday 15 September 2010

java - Delete multiple Rows containing a specific String -


I am trying to develop a code that can remove multiple rows of a specific string "POST". I am doing this:

  Private Zero process xcel file (file f_path) {file path = f_path; HSSFWorkbook wb = null; {FileInputStream = Try New FileInputStream (Path); Wb = new HSSFWorkbook (is); HSSFSheet Sheet = wb.getSheetAt (0); Int j = 0; For (line row: sheet) {for (cell cell: row) {count ++; If (cell.getCellType () == cell.CELL_TYPE_STRING) {if (cell.getRichStringCellValue (). GetString () .included ("POST")) {rowcount_post = row.getRowNum (); System.out.print ("ROW COUNT =" + rowcount_post); HSSFRow removal = right = sheet.lite (Panditikota_post); If (by removing! = Zero) {sheet.removeRow (for deletion); }}}}}} Hold (exception e) {JOptionPane.showMessageDialog (this, e.getMessage (), "error", JOptionPane.ERROR_MESSAGE); } {FileOutputStream fileOut = Try New FileOutputStream ("C: /juni.xls"); Wb.write (fileOut); } Hold (exception e) {JOptionPane.showMessageDialog (this, e.getMessage (), "save error", JOptionPane.ERROR_MESSAGE); }}   

It is a matter of fact that it only removes one line once it is possible that I can delete all the rows containing string POST?

Why do you have problems with removing them at one time? It does not seem very disabled ...

Anyway, I'm pretty sure that you still have to loop every cell to see if it's "post" or not. If you have a problem specifically removing a line at a time, you can save the index of rows that you want to delete in an array; Then use the array to delete the saved rows.

No comments:

Post a Comment