From 2fa190d507aaec606605382bfd5576af725e4253 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 7 Jan 2008 14:51:37 +0000 Subject: Fix bug #44070 - patch from Gian Carlo Pace git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@609620 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/usermodel/HSSFSheet.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/java/org') diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index b52fa1e5b2..ba9ff72a7e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -1202,6 +1202,12 @@ public class HSSFSheet row2Replace.createCellFromRecord( cellRecord ); sheet.addValueRecord( rowNum + n, cellRecord ); } + + // move comments if exist (can exist even if cell is null) + HSSFComment comment = getCellComment(rowNum, col); + if (comment != null) { + comment.setRow(rowNum + n); + } } } if ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 ); @@ -1671,7 +1677,21 @@ public class HSSFSheet * @return cell comment or null if not found */ public HSSFComment getCellComment(int row, int column){ - return HSSFCell.findCellComment(sheet, row, column); + // Don't call findCellComment directly, otherwise + // two calls to this method will result in two + // new HSSFComment instances, which is bad + HSSFRow r = getRow(row); + if(r != null) { + HSSFCell c = r.getCell((short)column); + if(c != null) { + return c.getCellComment(); + } else { + // No cell, so you will get new + // objects every time, sorry... + return HSSFCell.findCellComment(sheet, row, column); + } + } + return null; } } -- cgit v1.2.3