View | Details | Raw Unified | Return to bug 59665
Collapse All | Expand All

(-)a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java (-1 / +3 lines)
Lines 651-660 public final class InternalWorkbook { Link Here
651
        boundsheets.add(pos, boundsheets.remove(sheetNumber));
651
        boundsheets.add(pos, boundsheets.remove(sheetNumber));
652
        
652
        
653
        // also adjust order of Records, calculate the position of the Boundsheets via getBspos()...
653
        // also adjust order of Records, calculate the position of the Boundsheets via getBspos()...
654
        int pos0 = records.getBspos() - (boundsheets.size() - 1);
654
        int initialBspos = records.getBspos();
655
        int pos0 = initialBspos - (boundsheets.size() - 1);
655
        Record removed = records.get(pos0 + sheetNumber);
656
        Record removed = records.get(pos0 + sheetNumber);
656
        records.remove(pos0 + sheetNumber);
657
        records.remove(pos0 + sheetNumber);
657
		records.add(pos0 + pos, removed);
658
		records.add(pos0 + pos, removed);
659
        records.setBspos(initialBspos);
658
    }
660
    }
659
661
660
    /**
662
    /**
(-)a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (+13 lines)
Lines 1210-1213 public final class TestHSSFWorkbook extends BaseTestWorkbook { Link Here
1210
        wb = new HSSFWorkbook(new FileInputStream(file));
1210
        wb = new HSSFWorkbook(new FileInputStream(file));
1211
        assertCloseDoesNotModifyFile(filename, wb);
1211
        assertCloseDoesNotModifyFile(filename, wb);
1212
    }
1212
    }
1213
1214
    @Test
1215
    public void setSheetOrderToEnd() {
1216
        final HSSFWorkbook workbook = new HSSFWorkbook();
1217
        workbook.createSheet("A");
1218
        try {
1219
            for (int i=0; i<2*workbook.getInternalWorkbook().getRecords().size(); i++) {
1220
                workbook.setSheetOrder("A",0);
1221
            }
1222
        } catch (Exception e) {
1223
            fail("Moving a sheet to the end should not throw an exception, but threw " + e);
1224
        }
1225
    }
1213
}
1226
}

Return to bug 59665