I´m using jxl, jx:if-tags, inside jx:for. This (jx:if) is calling very often the following function and so I have huge performance problems! Used poi-version: poi-3.0.2-FINAL Class: org.apache.poi.hssf.usermodel.HSSFSheet Method: public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { Ist improvement: ---------------- line-number 1199: problem is call of row2Replace.getLastCellNum() on each iteration: for ( short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++ ) why you don´t use following code instead? I save 30 % time! short col=row.getFirstCellNum(); short lastCol=row.getLastCellNum(); while (true){ if(col > lastCol){ break; } IInd improvement: ---------------- line-number 1228: I removed the following code because I never work with comments, and most other people also. And I save again about 30 %. Perhaps you should make this optional by using boolean parameter? HSSFComment comment = getCellComment(rowNum, col); if (comment != null) { comment.setRow(rowNum + n); } With this 2 changes now I need 20 secs instead of 1 min!
I´ve changed this: short lastCol=row.getLastCellNum(); to this: int lastCol = row.getPhysicalNumberOfCells(); now, I need 2 secs! instead of 1 min!
Your proposed fix using physical number of cells won't work for cases where there are gaps in the row, with not all cells being defined. I've made some changes to HSSFSheet.shiftRows, committed to svn trunk. These should hopefully speed the method up, whilst ensuring that everything that needs to be moved is. Hopefully this does what you need?