diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index d0f4f0e64..ff7a39729 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 34023 - When shifting rows, update formulas on that sheet to point to the new location of those rows Support getting all the cells referenced by an AreaReference, not just the corner ones 43510 - Add support for named ranges in formulas, including non-contiguous named ranges 43937 - Add support for hiding and un-hiding sheets, and checking their current hidden status diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index f4d7c1b07..575bb6ba3 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 34023 - When shifting rows, update formulas on that sheet to point to the new location of those rows Support getting all the cells referenced by an AreaReference, not just the corner ones 43510 - Add support for named ranges in formulas, including non-contiguous named ranges 43937 - Add support for hiding and un-hiding sheets, and checking their current hidden status diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index b0d822286..5855a4937 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -28,6 +28,7 @@ import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.record.formula.Ptg; +import org.apache.poi.hssf.record.formula.ReferencePtg; import org.apache.poi.hssf.util.HSSFCellRangeAddress; import org.apache.poi.hssf.util.HSSFDataValidation; import org.apache.poi.hssf.util.Region; @@ -1215,12 +1216,52 @@ public class HSSFSheet // Update any formulas on this sheet that point to // rows which have been moved - - // Update any named ranges defined for this workbook - // that point to this sheet and had rows they reference - // moved - for(int i=0; i Row 11 + // So strings on row 11 unchanged, but reference in formula is + assertEquals("cell B1 (ref)", sheet.getRow(0).getCell((short)3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B1,\" (ref)\")", sheet.getRow(0).getCell((short)3).getCellFormula()); + assertEquals(0, sheet.getRow(1).getPhysicalNumberOfCells()); + + // still save b2 + assertEquals("cell B2 (ref)", sheet.getRow(11).getCell((short)3).getRichStringCellValue().toString()); + // but points to b12 + assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(11).getCell((short)3).getCellFormula()); + + assertEquals("cell B3 (ref)", sheet.getRow(2).getCell((short)3).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B3,\" (ref)\")", sheet.getRow(2).getCell((short)3).getCellFormula()); + + // one on a non-shifted row also updated + assertEquals("cell B2 (ref)", sheet.getRow(6).getCell((short)1).getRichStringCellValue().toString()); + assertEquals("CONCATENATE(B12,\" (ref)\")", sheet.getRow(6).getCell((short)1).getCellFormula()); + } }