/**
* 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
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();
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);