use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheets in project poi by apache.
the class XSSFWorkbook method setSheetOrder.
/**
* sets the order of appearance for a given sheet.
*
* @param sheetname the name of the sheet to reorder
* @param pos the position that we want to insert the sheet into (0 based)
*/
@Override
public void setSheetOrder(String sheetname, int pos) {
int idx = getSheetIndex(sheetname);
sheets.add(pos, sheets.remove(idx));
// Reorder CTSheets
CTSheets ct = workbook.getSheets();
XmlObject cts = ct.getSheetArray(idx).copy();
workbook.getSheets().removeSheet(idx);
CTSheet newcts = ct.insertNewSheet(pos);
newcts.set(cts);
//notify sheets
CTSheet[] sheetArray = ct.getSheetArray();
for (int i = 0; i < sheetArray.length; i++) {
sheets.get(i).sheet = sheetArray[i];
}
updateNamedRangesAfterSheetReorder(idx, pos);
updateActiveSheetAfterSheetReorder(idx, pos);
}