Lines 2943-2950
public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
Link Here
|
2943 |
@Override |
2943 |
@Override |
2944 |
public void shiftRows(int startRow, int endRow, final int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { |
2944 |
public void shiftRows(int startRow, int endRow, final int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { |
2945 |
XSSFVMLDrawing vml = getVMLDrawing(false); |
2945 |
XSSFVMLDrawing vml = getVMLDrawing(false); |
|
|
2946 |
removeOverwritten(vml, startRow, endRow, n); |
2947 |
doShifting(vml, startRow, endRow, n, copyRowHeight); |
2948 |
|
2949 |
|
2950 |
int sheetIndex = getWorkbook().getSheetIndex(this); |
2951 |
String sheetName = getWorkbook().getSheetName(sheetIndex); |
2952 |
FormulaShifter shifter = FormulaShifter.createForRowShift( |
2953 |
sheetIndex, sheetName, startRow, endRow, n, SpreadsheetVersion.EXCEL2007); |
2954 |
XSSFRowShifter rowShifter = new XSSFRowShifter(this, shifter); |
2946 |
|
2955 |
|
2947 |
// first remove all rows which will be overwritten |
2956 |
rowShifter.updateNamedRanges(); |
|
|
2957 |
rowShifter.updateFormulas(); |
2958 |
rowShifter.shiftMergedRegions(startRow, endRow, n); |
2959 |
rowShifter.updateConditionalFormatting(); |
2960 |
rowShifter.updateHyperlinks(); |
2961 |
|
2962 |
//rebuild the _rows map |
2963 |
Map<Integer, XSSFRow> map = new HashMap<Integer, XSSFRow>(); |
2964 |
for(XSSFRow r : _rows.values()) { |
2965 |
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory |
2966 |
final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR |
2967 |
map.put(rownumI, r); |
2968 |
} |
2969 |
_rows.clear(); |
2970 |
_rows.putAll(map); |
2971 |
} |
2972 |
|
2973 |
// remove all rows which will be overwritten |
2974 |
private void removeOverwritten(XSSFVMLDrawing vml, int startRow, int endRow, final int n){ |
2948 |
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { |
2975 |
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { |
2949 |
XSSFRow row = (XSSFRow)it.next(); |
2976 |
XSSFRow row = (XSSFRow)it.next(); |
2950 |
int rownum = row.getRowNum(); |
2977 |
int rownum = row.getRowNum(); |
Lines 2987-2996
public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
Link Here
|
2987 |
} |
3014 |
} |
2988 |
} |
3015 |
} |
2989 |
} |
3016 |
} |
2990 |
|
3017 |
} |
2991 |
// then do the actual moving and also adjust comments/rowHeight |
3018 |
|
2992 |
// we need to sort it in a way so the shifting does not mess up the structures, |
3019 |
// do the actual moving and also adjust comments/rowHeight |
2993 |
// i.e. when shifting down, start from down and go up, when shifting up, vice-versa |
3020 |
// we need to sort it in a way so the shifting does not mess up the structures, |
|
|
3021 |
// i.e. when shifting down, start from down and go up, when shifting up, vice-versa |
3022 |
private void doShifting(XSSFVMLDrawing vml, int startRow, int endRow, final int n, boolean copyRowHeight){ |
2994 |
SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<XSSFComment, Integer>(new Comparator<XSSFComment>() { |
3023 |
SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<XSSFComment, Integer>(new Comparator<XSSFComment>() { |
2995 |
@Override |
3024 |
@Override |
2996 |
public int compare(XSSFComment o1, XSSFComment o2) { |
3025 |
public int compare(XSSFComment o1, XSSFComment o2) { |
Lines 3012-3018
public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
Link Here
|
3012 |
} |
3041 |
} |
3013 |
} |
3042 |
} |
3014 |
}); |
3043 |
}); |
3015 |
|
|
|
3016 |
|
3044 |
|
3017 |
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { |
3045 |
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { |
3018 |
XSSFRow row = (XSSFRow)it.next(); |
3046 |
XSSFRow row = (XSSFRow)it.next(); |
Lines 3045-3055
public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
Link Here
|
3045 |
if(rownum < startRow || rownum > endRow) { |
3073 |
if(rownum < startRow || rownum > endRow) { |
3046 |
continue; |
3074 |
continue; |
3047 |
} |
3075 |
} |
3048 |
|
|
|
3049 |
if (!copyRowHeight) { |
3076 |
if (!copyRowHeight) { |
3050 |
row.setHeight((short)-1); |
3077 |
row.setHeight((short)-1); |
3051 |
} |
3078 |
} |
3052 |
|
|
|
3053 |
row.shift(n); |
3079 |
row.shift(n); |
3054 |
} |
3080 |
} |
3055 |
|
3081 |
|
Lines 3059-3088
public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
Link Here
|
3059 |
for(Map.Entry<XSSFComment, Integer> entry : commentsToShift.entrySet()) { |
3085 |
for(Map.Entry<XSSFComment, Integer> entry : commentsToShift.entrySet()) { |
3060 |
entry.getKey().setRow(entry.getValue()); |
3086 |
entry.getKey().setRow(entry.getValue()); |
3061 |
} |
3087 |
} |
3062 |
|
3088 |
|
3063 |
XSSFRowShifter rowShifter = new XSSFRowShifter(this); |
|
|
3064 |
|
3065 |
int sheetIndex = getWorkbook().getSheetIndex(this); |
3066 |
String sheetName = getWorkbook().getSheetName(sheetIndex); |
3067 |
FormulaShifter shifter = FormulaShifter.createForRowShift( |
3068 |
sheetIndex, sheetName, startRow, endRow, n, SpreadsheetVersion.EXCEL2007); |
3069 |
|
3070 |
rowShifter.updateNamedRanges(shifter); |
3071 |
rowShifter.updateFormulas(shifter); |
3072 |
rowShifter.shiftMergedRegions(startRow, endRow, n); |
3073 |
rowShifter.updateConditionalFormatting(shifter); |
3074 |
rowShifter.updateHyperlinks(shifter); |
3075 |
|
3076 |
//rebuild the _rows map |
3077 |
Map<Integer, XSSFRow> map = new HashMap<Integer, XSSFRow>(); |
3078 |
for(XSSFRow r : _rows.values()) { |
3079 |
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory |
3080 |
final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR |
3081 |
map.put(rownumI, r); |
3082 |
} |
3083 |
_rows.clear(); |
3084 |
_rows.putAll(map); |
3085 |
} |
3089 |
} |
|
|
3090 |
|
3086 |
|
3091 |
|
3087 |
private int shiftedRowNum(int startRow, int endRow, int n, int rownum) { |
3092 |
private int shiftedRowNum(int startRow, int endRow, int n, int rownum) { |
3088 |
// no change if before any affected row |
3093 |
// no change if before any affected row |