ASF Bugzilla – Attachment 37958 Details for
Bug 65453
[PATCH] Add support for java boxed tyes Number & Boolean in setCellValue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Represent null values of java's Number & Boolean as blank cells
Enhance_setCellValue_to_allow_javas_boxed_types.patch (text/plain), 4.61 KB, created by
Benjamin
on 2021-07-15 22:43:02 UTC
(
hide
)
Description:
Represent null values of java's Number & Boolean as blank cells
Filename:
MIME Type:
Creator:
Benjamin
Created:
2021-07-15 22:43:02 UTC
Size:
4.61 KB
patch
obsolete
>Index: poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java >--- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java (revision 18e10a1cddbef4baaa6146c07212263168bba1f0) >+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestCell.java (date 1626386254850) >@@ -79,6 +79,12 @@ > assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, > CellType.FORMULA, CellType.ERROR); > >+ cell.setCellValue(Integer.valueOf(42)); >+ assertEquals(42, cell.getNumericCellValue(), 0.0001); >+ assertEquals(CellType.NUMERIC, cell.getCellType()); >+ assertProhibitedValueAccess(cell, CellType.BOOLEAN, CellType.STRING, >+ CellType.FORMULA, CellType.ERROR); >+ > cell.setCellValue(false); > assertFalse(cell.getBooleanCellValue()); > assertEquals(CellType.BOOLEAN, cell.getCellType()); >@@ -86,6 +92,14 @@ > assertTrue(cell.getBooleanCellValue()); > assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, > CellType.FORMULA, CellType.ERROR); >+ >+ cell.setCellValue(Boolean.valueOf(false)); >+ assertFalse(cell.getBooleanCellValue()); >+ assertEquals(CellType.BOOLEAN, cell.getCellType()); >+ cell.setCellValue(Boolean.valueOf(true)); >+ assertTrue(cell.getBooleanCellValue()); >+ assertProhibitedValueAccess(cell, CellType.NUMERIC, CellType.STRING, CellType.BOOLEAN, >+ CellType.FORMULA, CellType.ERROR); > > cell.setCellValue(factory.createRichTextString("Foo")); > assertEquals("Foo", cell.getRichStringCellValue().getString()); >@@ -138,6 +152,14 @@ > cell.setCellValue((String)null); > assertEquals("", cell.getStringCellValue()); > assertEquals(CellType.BLANK, cell.getCellType()); >+ >+ cell.setCellValue((Number)null); >+ assertEquals("", cell.getStringCellValue()); >+ assertEquals(CellType.BLANK, cell.getCellType()); >+ >+ cell.setCellValue((Boolean)null); >+ assertEquals("", cell.getStringCellValue()); >+ assertEquals(CellType.BLANK, cell.getCellType()); > > cell.setCellValue((LocalDate)null); > assertNull(cell.getLocalDateTimeCellValue()); >Index: poi/src/main/java/org/apache/poi/ss/usermodel/Cell.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/Cell.java b/poi/src/main/java/org/apache/poi/ss/usermodel/Cell.java >--- a/poi/src/main/java/org/apache/poi/ss/usermodel/Cell.java (revision 18e10a1cddbef4baaa6146c07212263168bba1f0) >+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/Cell.java (date 1626386254855) >@@ -130,6 +130,23 @@ > */ > void setCellValue(double value); > >+ /** >+ * Set a numeric value for the cell. >+ * >+ * Allows usage of boxed java types for numeric values and will convert the value using {@link Number#doubleValue()} >+ * to call {@link Cell#setCellValue(double)}. >+ * >+ * @param value if null, then {@link Cell#setBlank()} is called. >+ * @see Cell#setCellValue(double) >+ * */ >+ default void setCellValue(Number value) { >+ if (null == value) { >+ setBlank(); >+ return; >+ } >+ setCellValue(value.doubleValue()); >+ } >+ > /** > * <p>Converts the supplied date to its equivalent Excel numeric value and sets > * that into the cell.</p> >@@ -325,6 +342,23 @@ > */ > void setCellValue(boolean value); > >+ /** >+ * Set a boolean value for the cell. >+ * >+ * Allows usage of boxed java type {@link Boolean} and will convert the value using {@link Boolean#booleanValue()} >+ * to call {@link Cell#setCellValue(boolean)}. >+ * >+ * @param value if null, then {@link Cell#setBlank()} is called. >+ * @see Cell#setCellValue(boolean) >+ * */ >+ default void setCellValue(Boolean value) { >+ if (null == value) { >+ setBlank(); >+ return; >+ } >+ setCellValue(value.booleanValue()); >+ } >+ > /** > * Set a error value for the cell > *
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 65453
: 37958