SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer wrote:You're thinking way too complicated:
Edit: ... which is just what David suggests.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Yes, but what does that bring me? I have 6 sheets and I have to create 6 workbooks out of those 6 sheets in the master excel.
...delete all sheets except the last one...
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer wrote:In that case, you'll need to open the file N times if it contains N sheets, and each time remove those N-1 sheets you don't want to save.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer wrote:That looks like you're getting closer. But "workbook.removeSheetAt(i)" should be "workbook.removeSheetAt(0)", or you'll again run into the problem you described in the first post.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer wrote:We had already established that each call to removeSheetAt leads to all pages being renumbered, hadn't we?
If you really don't want to contemplate taking my advice of repeatedly using removeSheetAt(0) (why not, by the way?), then you can start the loop at "newWB.getNumberOfSheets()-1" and count down to 0 from there.
But you should still try to understand why it doesn't work the way you're trying to do it. Maybe you can write down on paper the numbers of the sheets, before and after each iteration and renumbering, and what the value of "i" would be at each step (and -cruciallly!- what the call to getNumberOfSheets returns).
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
I even tried replacing the i with 0 as mentioned in your post, but it ran till the third sheet and the remaining sheets (4, 5 and 6) were created with the content of the 3rd sheet.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ulf Dittmer wrote:
I even tried replacing the i with 0 as mentioned in your post, but it ran till the third sheet and the remaining sheets (4, 5 and 6) were created with the content of the 3rd sheet.
That's a good start - note how you didn't get an exception any longer? That's an improvement, isn't it? The other missing piece is the call to "getNumberOfSheets" in the loop - that number changes each time a sheet is removed. So the loop must not stop at the current number of sheets, it must stop at the initial number of sheets before you removed any. Since that number is lost once you start removing sheets, you need to store it before the loop.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Don't get me started about those stupid light bulbs. |