Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ExcelParser does not read double < .0001 from Excel cell #73

Closed
wants to merge 1 commit into from

3 participants

F. Meyer Edson Tirelli Michael Anstis
F. Meyer

I've created a new xls based on basic workbook to reproduce this bug.

I think we should create a nice way to test this stuff. I couldn't test the parser as properly because the strong dependence between the ExcelParser and the DefaultRuleSheetListener which lack of testing

F. Meyer

I also removed an unused piece of code.

Edson Tirelli
Owner

@fmeyer I am unable to apply your PR cleanly. Can you please fix and re-submit? Thanks!

Michael Anstis manstis closed this
Michael Anstis
Owner

Merged into droolsjbpm/master. Thanks for the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  drools-decisiontables/src/main/java/org/drools/decisiontable/DecisionTableProviderImpl.java
View
@@ -2,7 +2,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.Reader;
import org.drools.builder.DecisionTableConfiguration;
32 drools-decisiontables/src/main/java/org/drools/decisiontable/parser/xls/ExcelParser.java
View
@@ -24,6 +24,8 @@
import java.util.Map;
import jxl.Cell;
+import jxl.CellType;
+import jxl.NumberCell;
import jxl.Range;
import jxl.Sheet;
import jxl.Workbook;
@@ -110,6 +112,7 @@ private void processSheet(Sheet sheet,
row.length );
for ( int cellNum = 0; cellNum < row.length; cellNum++ ) {
Cell cell = row[cellNum];
+ double num = 0;
Range merged = getRangeIfMerged( cell,
mergedRanges );
@@ -120,13 +123,21 @@ private void processSheet(Sheet sheet,
i,
cellNum,
topLeft.getContents(),
- topLeft.getColumn() );
+ topLeft.getColumn() );
} else {
- newCell( listeners,
- i,
- cellNum,
- cell.getContents(),
- DataListener.NON_MERGED );
+ if (cell.getType() == CellType.NUMBER) {
+ NumberCell nc = (NumberCell) cell;
+ num = nc.getValue();
+ }
+ if ( Math.abs(num) - Math.ceil(num) != 0 ) {
+ newCell(listeners, i, cellNum, String.valueOf(num), DataListener.NON_MERGED );
+ } else {
+ newCell( listeners,
+ i,
+ cellNum,
+ cell.getContents(),
+ DataListener.NON_MERGED );
+ }
}
}
}
@@ -146,14 +157,7 @@ Range getRangeIfMerged(Cell cell,
return null;
}
- static String removeTrailingZero(String stringVal) {
- if ( stringVal.endsWith( ".0" ) ) {
- stringVal = stringVal.substring( 0,
- stringVal.length() - 2 );
- }
- return stringVal;
- }
-
+
private void finishSheet(List< ? extends DataListener> listeners) {
for ( DataListener listener : listeners ) {
listener.finishSheet();
23 drools-decisiontables/src/test/java/org/drools/decisiontable/SpreadsheetCompilerUnitTest.java
View
@@ -20,6 +20,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.drools.decisiontable.parser.xls.ExcelParser;
+import org.drools.template.parser.DataListener;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -132,4 +134,25 @@ public void testLoadBasicWithMergedCells() {
}
+
+ @Test
+ public void testProcessSheetForExtremeLowNumbers() {
+ final SpreadsheetCompiler converter = new SpreadsheetCompiler();
+ final InputStream stream = this.getClass().getResourceAsStream("/data/BasicWorkbook_with_low_values.xls" );
+ final String drl = converter.compile( stream,
+ InputType.XLS );
+ assertNotNull( drl );
+ System.out.println(drl);
+
+
+ // Should parse the correct number
+ assertTrue( drl.indexOf( "myObject.size() < 0" ) == -1 );
+
+ assertTrue( drl.indexOf( "myObject.size() < 8.0E-11" ) > -1 );
+ assertTrue( drl.indexOf( "myObject.size() < 9.0E-7" ) > -1 );
+ assertTrue( drl.indexOf( "myObject.size() < 3.0E-4" ) > -1 );
+
+ }
+
+
}
25 drools-decisiontables/src/test/java/org/drools/decisiontable/parser/xls/ExcelParserTest.java
View
@@ -16,19 +16,19 @@
package org.drools.decisiontable.parser.xls;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import java.util.List;
import java.util.Map;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import static org.junit.Assert.*;
import jxl.Cell;
import jxl.CellType;
import jxl.Range;
import jxl.format.CellFormat;
import org.drools.template.parser.DataListener;
+import org.junit.Test;
/**
*
@@ -36,23 +36,6 @@
* covered by integration tests.
*/
public class ExcelParserTest {
-
- @Test
- public void testRemoveTrailingZero() {
- String test = "1.0";
- assertEquals( "1",
- ExcelParser.removeTrailingZero( test ) );
-
- test = "42.0";
- assertEquals( "42",
- ExcelParser.removeTrailingZero( test ) );
-
- test = "42";
- assertEquals( "42",
- ExcelParser.removeTrailingZero( test ) );
-
- }
-
/**
* This should test to see if a cell is in a certain range or not.
* If it is in a merged range, then it should return the top left cell.
BIN  drools-decisiontables/src/test/resources/data/BasicWorkbook_with_low_values.xls
View
Binary file not shown
Something went wrong with that request. Please try again.