Bug 44461

Summary: shiftRows don't copy the CellStyle
Product: POI Reporter: Sven Nissel <sven>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 3.0-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Sven Nissel 2008-02-21 02:41:51 UTC
If I use HSSFSheet#shiftRows() it will not copy the CellStyle of the row befor. 

I fix it very bad and slowly this way:
public void insertRowAfter(int rowNum) {
		HSSFRow row = sheet.getRow(rowNum);
		sheet.shiftRows(rowNum + 1, sheet.getLastRowNum(), 1, true, true);
		
		HSSFRow newRow = sheet.getRow(rowNum + 1);
		for (short i = 0; i <= row.getLastCellNum(); i++) {
			HSSFCell cell = row.getCell(i);
			HSSFCell newCell = newRow.getCell(i);
			if (cell != null) {
				if (newCell == null)
					newCell = newRow.createCell(i);
				newCell.setCellStyle(cell.getCellStyle());
			}
		}
	}

Is this a bug- or future- request?
Comment 1 Dominik Stadler 2015-05-01 20:09:29 UTC
A quick test showed that this seems to work correctly with the current version of POI, please try it again with at least POI 3.12beta1 and reopen this bug with some more information if it still does not work for you.