• Post Reply Bookmark Topic Watch Topic
  • New Topic

Apache POI, deleting Excel Rows  RSS feed

 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm simply just trying to get this program to delete a row after a button press. Using Apache POI and Excel.xlsx. Any help on what I'm doing wrong. I also tried it without add the shiftRow method.

Thanks

 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What issue are you seeing?
Does it fail to delete the row, throw an exception, or something else?
 
Knute Snortum
Sheriff
Posts: 3971
97
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens/doesn't happen when this code is executed?  Could you TellTheDetails? (that's a link)
 
Tim Moores
Saloon Keeper
Posts: 3832
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is happening when you run this code, and what did you expect to happen instead? Can you post code that resembles an SSCCE (<- that's a link), especially showing how the file is opened and saved?

(Update: What they said :-) I didn't see the previous posts when I wrote this.)
 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:What issue are you seeing?
Does it fail to delete the row, throw an exception, or something else?


Its not giving me any error, it just doesn't work.
 
Tim Moores
Saloon Keeper
Posts: 3832
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, since the code you posted only contains two lines that use POI, but none of the crucial loading and saving of the sheet:
Can you post an SSCCE that demonstrates the issue, especially showing how the file is opened and saved?
 
Knute Snortum
Sheriff
Posts: 3971
97
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://coderanch.com/wiki/660111/Doesnt-Work-Useless

"Doesn't work" could mean:
1) Row is cleared but it doesn't get shifted up
2) No action is performed at all
3) Any number of things

Could you be more descriptive about exactly what doesn't work?
 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:In that case, since the code you posted only contains two lines that use POI, but none of the crucial loading and saving of the sheet:
Can you post an SSCCE that demonstrates the issue, especially showing how the file is opened and saved?


This is a function of the code that is called by main. This is a big program for my job, so a lot of things here are/maybe not needed. I'm working on the rough draft. I'll iron it all out once everything works.

 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a start point, put some debug logging in there, even some simple println statements will be enough to show that the code shown is actually being executed.
 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:https://coderanch.com/wiki/660111/Doesnt-Work-Useless

"Doesn't work" could mean:
1) Row is cleared but it doesn't get shifted up
2) No action is performed at all
3) Any number of things

Could you be more descriptive about exactly what doesn't work?


2) No action is performed at all.
 
Knute Snortum
Sheriff
Posts: 3971
97
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does "done" print?
 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Does "done" print?


Yes, I added it just to make sure that the line of code was working.
 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony Johnson wrote:
2) No action is performed at all.


But what does that mean?
What action do you expect to see?

All the above code shows is the removal of a row from the sheet, but there's nothing there to show us how you determine whether the row is removed.
Do you save the sheet and then check?
Is there something else you expect to see?

(And I missed you already had a println statement in there! )
 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
Anthony Johnson wrote:
2) No action is performed at all.


But what does that mean?
What action do you expect to see?

All the above code shows is the removal of a row from the sheet, but there's nothing there to show us how you determine whether the row is removed.
Do you save the sheet and then check?
Is there something else you expect to see?

(And I missed you already had a println statement in there! )


So I add a structure type/number to the construction notes, lets say row 11. If the person decides they don't want to use that structure type or used the wrong structure number, they can press "cancel". "Cancel" should remove delete that row. The reason that row needs to be deleted because below it is an empty row, waiting for the next structure to be added. If I can't get it to delete, a blank row will continue to be added. Then I will have more blank rows than I need. If that makes any sense.
 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it makes sense, I'm just not sure where exactly you are expecting to see the result of this deletion.

POI (for example) has no GUI, so is this your own GUI, in which case I would look at whether that side of things is going wrong.
Also, log what row it is removing in that action listener.  It's possible that is incorrect?

You might also want to do a quick test bit of code that opens an existing spreadsheet with a handful of rows, deletes one of them in the middle, and then saves it.  Look at the result just to see what POI does in the remove() operation and whether the shift is needed at all.
 
Knute Snortum
Sheriff
Posts: 3971
97
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the row to remove the last row in the sheet?  If so, try:
 
Anthony Johnson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I got it. The file was closed before before it could write the updates. Its not working perfectly, but I think I can figure it out from here.
 
Knute Snortum
Sheriff
Posts: 3971
97
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!  Thanks for the update.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!