From: Javen O'Neal Date: Mon, 2 Nov 2015 10:47:19 +0000 (+0000) Subject: bug58348: add test for copying formula with unregistered UDF X-Git-Tag: REL_3_14_BETA1~166 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=83aaa1937f31b101c31394782fbc0e29288e5627;p=poi.git bug58348: add test for copying formula with unregistered UDF git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711939 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java index 1de2982dcd..68ec6bc6c4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -121,6 +121,9 @@ public final class XSSFCell implements Cell { /** * Copy cell value, formula, and style, from srcCell per cell copy policy * If srcCell is null, clears the cell value and cell style per cell copy policy + * + * This does not shift references in formulas. Use {@link XSSFRowShifter} to shift references in formulas. + * * @param srcCell * @param policy * @throws IllegalArgumentException if copy cell style and srcCell is from a different workbook diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java index 09dab72691..8d0d439d02 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -529,6 +529,19 @@ public final class TestXSSFCell extends BaseTestXCell { assertEquals(Cell.CELL_TYPE_NUMERIC, destCell.getCellType()); } + @Test + public final void testCopyCellFrom_CellCopyPolicy_formulaWithUnregisteredUDF() { + setUp_testCopyCellFrom_CellCopyPolicy(); + + srcCell.setCellFormula("MYFUNC2(123, $A5, Sheet1!$B7)"); + + // Copy formula verbatim (no shifting). This is okay because copyCellFrom is Internal. + // Users should use higher-level copying functions to row- or column-shift formulas. + final CellCopyPolicy policy = new CellCopyPolicy.Builder().cellFormula(true).build(); + destCell.copyCellFrom(srcCell, policy); + assertEquals("MYFUNC2(123, $A5, Sheet1!$B7)", destCell.getCellFormula()); + } + @Test public final void testCopyCellFrom_CellCopyPolicy_style() { setUp_testCopyCellFrom_CellCopyPolicy(); @@ -637,7 +650,7 @@ public final class TestXSSFCell extends BaseTestXCell { private final void setUp_testCopyCellFrom_CellCopyPolicy() { @SuppressWarnings("resource") final XSSFWorkbook wb = new XSSFWorkbook(); - final XSSFRow row = wb.createSheet().createRow(0); + final XSSFRow row = wb.createSheet("Sheet1").createRow(0); srcCell = row.createCell(0); destCell = row.createCell(1);