• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using ApachePOI

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an excel sheet which has 30 rows in which i add more rows using ApachePOI. Now my Java program gets the last row number, increase it by one and adds data for that row.
When i go to the excel sheet after adding an row, its added perfectly. But when i delete that row from excel sheet, again add an row using the program, the row is added below the
row which i deleted i.e. it also considers the blank row as row.
Lets say i add 31st row to my excel sheet, delete it from the excel sheet and when i again run the program, the new row is added to 32nd row instead of 31st.
Any idea why this could be happening and how to resolve it?
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you identify the "last row"?

When you press Ctrl-End in Excel, it goes to the "last cell". However, sometimes when I delete rows from a sheet, Ctrl-End selects a cell which is beyond the last cell actually containing some value. It seems Excel keeps track of the rows/columns being used in the past.

If you expect the data to be continuous, it should be always possible to navigate to the last row by inspecting values in individual cells, until first empty row is detected. If there can be empty rows in your data, you might start from the cell you're getting as the last one using your current approach and go up until you encounter a non-empty row.
 
reply
    Bookmark Topic Watch Topic
  • New Topic