Lines 570-576
Link Here
|
570 |
ctRow = prev.getCTRow(); |
570 |
ctRow = prev.getCTRow(); |
571 |
ctRow.set(CTRow.Factory.newInstance()); |
571 |
ctRow.set(CTRow.Factory.newInstance()); |
572 |
} else { |
572 |
} else { |
573 |
ctRow = worksheet.getSheetData().addNewRow(); |
573 |
if(_rows.isEmpty() || rownum > _rows.lastKey()) { |
|
|
574 |
// we can append the new row at the end |
575 |
ctRow = worksheet.getSheetData().addNewRow(); |
576 |
} else { |
577 |
// get number of rows where row index < rownum |
578 |
// --> this tells us where our row should go |
579 |
int idx = _rows.headMap(rownum).size(); |
580 |
ctRow = worksheet.getSheetData().insertNewRow(idx); |
581 |
} |
574 |
} |
582 |
} |
575 |
XSSFRow r = new XSSFRow(ctRow, this); |
583 |
XSSFRow r = new XSSFRow(ctRow, this); |
576 |
r.setRowNum(rownum); |
584 |
r.setRowNum(rownum); |
Lines 1496-1502
Link Here
|
1496 |
|
1504 |
|
1497 |
for(XSSFCell cell : cellsToDelete) row.removeCell(cell); |
1505 |
for(XSSFCell cell : cellsToDelete) row.removeCell(cell); |
1498 |
|
1506 |
|
|
|
1507 |
int idx = _rows.headMap(row.getRowNum()).size(); |
1499 |
_rows.remove(row.getRowNum()); |
1508 |
_rows.remove(row.getRowNum()); |
|
|
1509 |
worksheet.getSheetData().removeRow(idx); |
1500 |
} |
1510 |
} |
1501 |
|
1511 |
|
1502 |
/** |
1512 |
/** |
Lines 2355-2361
Link Here
|
2355 |
*/ |
2365 |
*/ |
2356 |
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support |
2366 |
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support |
2357 |
public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { |
2367 |
public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { |
2358 |
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { |
2368 |
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { |
2359 |
XSSFRow row = (XSSFRow)it.next(); |
2369 |
XSSFRow row = (XSSFRow)it.next(); |
2360 |
int rownum = row.getRowNum(); |
2370 |
int rownum = row.getRowNum(); |
2361 |
if(rownum < startRow) continue; |
2371 |
if(rownum < startRow) continue; |
Lines 2365-2370
Link Here
|
2365 |
} |
2375 |
} |
2366 |
|
2376 |
|
2367 |
if (removeRow(startRow, endRow, n, rownum)) { |
2377 |
if (removeRow(startRow, endRow, n, rownum)) { |
|
|
2378 |
// remove row from worksheet.getSheetData row array |
2379 |
int idx = _rows.headMap(row.getRowNum()).size(); |
2380 |
worksheet.getSheetData().removeRow(idx); |
2381 |
// remove row from _rows |
2368 |
it.remove(); |
2382 |
it.remove(); |
2369 |
} |
2383 |
} |
2370 |
else if (rownum >= startRow && rownum <= endRow) { |
2384 |
else if (rownum >= startRow && rownum <= endRow) { |
Lines 2689-2695
Link Here
|
2689 |
for(XSSFRow row : _rows.values()){ |
2703 |
for(XSSFRow row : _rows.values()){ |
2690 |
row.onDocumentWrite(); |
2704 |
row.onDocumentWrite(); |
2691 |
} |
2705 |
} |
2692 |
ensureRowOrdering(); |
|
|
2693 |
|
2706 |
|
2694 |
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); |
2707 |
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); |
2695 |
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorksheet.type.getName().getNamespaceURI(), "worksheet")); |
2708 |
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorksheet.type.getName().getNamespaceURI(), "worksheet")); |
Lines 2701-2739
Link Here
|
2701 |
} |
2714 |
} |
2702 |
|
2715 |
|
2703 |
/** |
2716 |
/** |
2704 |
* ensure that the array of CTRow written to CTSheetData is ordered by row index |
|
|
2705 |
*/ |
2706 |
private void ensureRowOrdering(){ |
2707 |
CTSheetData sheetData = worksheet.getSheetData(); |
2708 |
// check if row indexes in CTSheetData match the internal model: |
2709 |
// rows in the internal model (_rows) are always ordered while |
2710 |
// CTRow beans held by CTSheetData may be not, for example, user can |
2711 |
// insert rows in random order, shift rows after insertion, etc. |
2712 |
boolean isOrdered = true; |
2713 |
if(sheetData.sizeOfRowArray() != _rows.size()) isOrdered = false; |
2714 |
else { |
2715 |
int i = 0; |
2716 |
for (XSSFRow row : _rows.values()) { |
2717 |
CTRow c1 = row.getCTRow(); |
2718 |
CTRow c2 = sheetData.getRowArray(i++); |
2719 |
if (c1.getR() != c2.getR()){ |
2720 |
isOrdered = false; |
2721 |
break; |
2722 |
} |
2723 |
} |
2724 |
} |
2725 |
|
2726 |
if(!isOrdered){ |
2727 |
CTRow[] cArray = new CTRow[_rows.size()]; |
2728 |
int i = 0; |
2729 |
for(XSSFRow row : _rows.values()){ |
2730 |
cArray[i++] = row.getCTRow(); |
2731 |
} |
2732 |
sheetData.setRowArray(cArray); |
2733 |
} |
2734 |
} |
2735 |
|
2736 |
/** |
2737 |
* @return true when Autofilters are locked and the sheet is protected. |
2717 |
* @return true when Autofilters are locked and the sheet is protected. |
2738 |
*/ |
2718 |
*/ |
2739 |
public boolean isAutoFilterLocked() { |
2719 |
public boolean isAutoFilterLocked() { |