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

(-)src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (+11 lines)
Lines 967-970 Link Here
967
          throw new RuntimeException("You cannot reference columns with an index of less then 0.");
967
          throw new RuntimeException("You cannot reference columns with an index of less then 0.");
968
      }
968
      }
969
    }
969
    }
970
971
    /**
972
     * Sets the cells row.  Should be really careful with this.
973
     *
974
     * @param row the new row number
975
     */
976
    public void setRow(int row) {
977
	if (record != null) {
978
	    record.setRow(row);
979
	}
980
    }
970
}
981
}
(-)src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (+7 lines)
Lines 253-258 Link Here
253
        {
253
        {
254
            row.setRowNumber(rowNum);   // used only for KEY comparison (HSSFRow)
254
            row.setRowNumber(rowNum);   // used only for KEY comparison (HSSFRow)
255
        }
255
        }
256
	if (cells != null) {
257
	    Iterator i = cells.values().iterator();
258
	    while (i.hasNext()) {
259
		HSSFCell cell = (HSSFCell)i.next();
260
		cell.setRow(rowNum);
261
	    }
262
	}
256
    }
263
    }
257
264
258
    /**
265
    /**
(-)src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (+37 lines)
Lines 829-832 Link Here
829
     public void setMargin(short margin, double size) {
829
     public void setMargin(short margin, double size) {
830
       getSheet().setMargin(margin, size);
830
       getSheet().setMargin(margin, size);
831
      }
831
      }
832
833
    /**
834
     * Shifts rows between startRow and endRow n number of rows.
835
     * If you use a negative number, it will shift rows up.
836
     *
837
     * @param startRow the row to start shifting
838
     * @param endRow the row to end shifting
839
     * @param n the number of rows to shift
840
     */
841
    public void shiftRows(int startRow, int endRow, int n) {
842
	int s, e, inc;
843
	if (n < 0) {
844
	    s = startRow;
845
	    e = endRow;
846
	    inc = 1;
847
	} else {
848
	    s = endRow;
849
	    e = startRow;
850
	    inc = -1;
851
	}
852
	for (int rowNum = s; rowNum >= startRow && rowNum <= endRow; rowNum+=inc) {
853
	    System.out.println(rowNum);
854
	    HSSFRow row = getRow(rowNum);
855
	    HSSFRow row2Replace = getRow(rowNum + n);
856
	    if (row2Replace != null) {
857
		removeRow(row2Replace);
858
	    }
859
	    if (row != null) {
860
		System.out.println("Shifting " + rowNum);
861
		row.setRowNum(rowNum + n);
862
		System.out.println(row.getPhysicalNumberOfCells());
863
	    } 
864
	}
865
	if (endRow + n > lastrow) lastrow = endRow + n;
866
	if (startRow + n > firstrow) firstrow = startRow + n;
867
	System.out.println(firstrow + " " + lastrow);
868
    }
832
}
869
}

Return to bug 13332