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
This commit is contained in:
Javen O'Neal 2015-11-02 10:47:19 +00:00
parent f7fbfcd5ea
commit 54113431b5
2 changed files with 17 additions and 1 deletions

View File

@ -121,6 +121,9 @@ public final class XSSFCell implements Cell {
/** /**
* Copy cell value, formula, and style, from srcCell per cell copy policy * 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 * 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 srcCell
* @param policy * @param policy
* @throws IllegalArgumentException if copy cell style and srcCell is from a different workbook * @throws IllegalArgumentException if copy cell style and srcCell is from a different workbook

View File

@ -529,6 +529,19 @@ public final class TestXSSFCell extends BaseTestXCell {
assertEquals(Cell.CELL_TYPE_NUMERIC, destCell.getCellType()); 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 @Test
public final void testCopyCellFrom_CellCopyPolicy_style() { public final void testCopyCellFrom_CellCopyPolicy_style() {
setUp_testCopyCellFrom_CellCopyPolicy(); setUp_testCopyCellFrom_CellCopyPolicy();
@ -637,7 +650,7 @@ public final class TestXSSFCell extends BaseTestXCell {
private final void setUp_testCopyCellFrom_CellCopyPolicy() { private final void setUp_testCopyCellFrom_CellCopyPolicy() {
@SuppressWarnings("resource") @SuppressWarnings("resource")
final XSSFWorkbook wb = new XSSFWorkbook(); final XSSFWorkbook wb = new XSSFWorkbook();
final XSSFRow row = wb.createSheet().createRow(0); final XSSFRow row = wb.createSheet("Sheet1").createRow(0);
srcCell = row.createCell(0); srcCell = row.createCell(0);
destCell = row.createCell(1); destCell = row.createCell(1);