diff options
author | PJ Fanning <fanningpj@apache.org> | 2025-02-13 10:53:16 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2025-02-13 10:53:16 +0000 |
commit | 3a3effca652a8d687f90c47b829acf5329807926 (patch) | |
tree | 22210e793968fe7842f1b7d5c84d515ba0887a02 /poi/src/test/java | |
parent | d6d403371af1f69624229ab75629b4ff932d1041 (diff) | |
download | poi-3a3effca652a8d687f90c47b829acf5329807926.tar.gz poi-3a3effca652a8d687f90c47b829acf5329807926.zip |
[bug-69583] when copying cells with dates - prefer using the numeric data directly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923780 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src/test/java')
-rw-r--r-- | poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtilCopy.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtilCopy.java b/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtilCopy.java index ea214e815d..14d3fa00a1 100644 --- a/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtilCopy.java +++ b/poi/src/test/java/org/apache/poi/ss/util/BaseTestCellUtilCopy.java @@ -146,6 +146,33 @@ public abstract class BaseTestCellUtilCopy { wb.close(); } + @Test + public final void testCopyCellTime() throws IOException { + try( + Workbook srcWb = createNewWorkbook(); + Workbook destWb = createNewWorkbook() + ) { + final Row rowS = srcWb.createSheet("Sheet1").createRow(0); + final Row rowD = destWb.createSheet("Sheet1").createRow(0); + srcCell = rowS.createCell(0); + destCell = rowD.createCell(0); + + srcCell.setCellValue(22.0/24.0); + + final CellStyle style = srcWb.createCellStyle(); + style.setDataFormat((short) 0x12); // time format + srcCell.setCellStyle(style); + + final CreationHelper createHelper = srcWb.getCreationHelper(); + + final CellCopyPolicy policy = new CellCopyPolicy.Builder().build(); + CellUtil.copyCell(srcCell, destCell, policy, new CellCopyContext()); + + assertEquals(srcCell.getNumericCellValue(), destCell.getNumericCellValue()); + assertEquals(srcCell.getCellStyle().getDataFormatString(), destCell.getCellStyle().getDataFormatString()); + } + } + private void setUp_testCopyCellFrom_CellCopyPolicy() { @SuppressWarnings("resource") final Workbook wb = createNewWorkbook(); |