mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[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
This commit is contained in:
parent
d6d403371a
commit
3a3effca65
@ -727,6 +727,7 @@ public class DateUtil {
|
||||
case 0x0f:
|
||||
case 0x10:
|
||||
case 0x11:
|
||||
// the 0x12 to 0x15 formats are time (only) formats
|
||||
case 0x12:
|
||||
case 0x13:
|
||||
case 0x14:
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user