]> source.dussan.org Git - poi.git/commitdiff
bug58348: add test for copying formula with unregistered UDF
authorJaven O'Neal <onealj@apache.org>
Mon, 2 Nov 2015 10:47:19 +0000 (10:47 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 2 Nov 2015 10:47:19 +0000 (10:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711939 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java

index 1de2982dcdd8d7e37d6237e2ebaa0cf6ddeecc7c..68ec6bc6c42d3598ca590cde162b308f7091d6ec 100644 (file)
@@ -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
index 09dab7269148cdf0486c44ab024e52ac5a9abbbf..8d0d439d02f7d0349a181875a0d104370e031642 100644 (file)
@@ -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);