GerardDellemann commented on a change in pull request #234: MM-82 Detect Column 
Types
URL: https://github.com/apache/metamodel/pull/234#discussion_r354288897
 
 

 ##########
 File path: excel/src/main/java/org/apache/metamodel/excel/ExcelUtils.java
 ##########
 @@ -237,13 +292,34 @@ public static String getCellValue(Workbook wb, Cell 
cell) {
         return result;
     }
 
+    public static Object getCellValueChecked(final Workbook wb, final Cell 
cell, final ColumnType expectedColumnType) {
+        final Object value = getCellValueAsObject(wb, cell);
+        if (value == null || 
value.getClass().equals(expectedColumnType.getJavaEquivalentClass())) {
+            return value;
+        }
+
+        if (!(value.getClass().equals(Integer.class) && expectedColumnType
+                .getJavaEquivalentClass()
+                .equals(Double.class)) && logger.isWarnEnabled()) {
+            // Don't log when a Integer value is in a Double column type
+            final String cellCoordinate = "(" + cell.getRowIndex() + "," + 
cell.getColumnIndex() + ")";
+            final String warning = String
+                    .format("Cell %s has the value '%s' of data type '%s', 
which doesn't match the detected column's "
+                            + "data type '%s'. This cell gets value NULL in 
the DataSet.", cellCoordinate, value, value
+                            .getClass()
+                            .getSimpleName(), expectedColumnType);
+            logger.warn(warning);
+        }
+        return null;
+    }
+
     private static String getFormulaCellValue(Workbook wb, Cell cell) {
         // first try with a cached/precalculated value
         try {
             double numericCellValue = cell.getNumericCellValue();
             // TODO: Consider not formatting it, but simple using
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to