Skip to content

Commit e4dfca7

Browse files
bugfix: values representing numbers should be provided as instances of java.lang.Double
1 parent 05a3152 commit e4dfca7

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ publishing {
5050
maven(MavenPublication) {
5151
groupId = 'de.inetsoftware'
5252
artifactId = 'exceljconnect'
53-
version = '1.3'
53+
version = '1.4'
5454
from components.java
5555
pom {
5656
name = 'Excel driver for Java'

src/com/inet/excel/ExcelDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class ExcelDriver implements Driver {
3535
public static final String URL_PREFIX = "jdbc:inetexcel:";
3636
public static final String DRIVER_NAME = "inetexcel";
3737
public static final int MAJOR_VERSION = 1;
38-
public static final int MINOR_VERSION = 3;
38+
public static final int MINOR_VERSION = 4;
3939

4040
/** Throws exception indicating that requested operation is not supported.
4141
* @throws SQLException exception indicating that requested operation is not supported.

src/com/inet/excel/parser/ExcelParser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public String getFileName() {
102102
public List<String> getColumnNames( String sheetName ) {
103103
try( ZipFile zipFile = new ZipFile( filePath.toString() ) ) {
104104
initSheetData( zipFile );
105+
initStyles( zipFile );
105106
initDimensionAndColumnNames( zipFile, sheetName );
106107
return Collections.unmodifiableList( sheetNamesToColumnNames.get( sheetName ) );
107108
} catch( IOException ex ) {
@@ -184,6 +185,7 @@ public List<List<Object>> getRows( String sheetName, int firstRowIndex, int last
184185
initSheetData( zipFile );
185186
initStyles( zipFile );
186187
initDimensionAndColumnNames( zipFile, sheetName );
188+
initColumnTypes( zipFile, sheetName );
187189
if( hasHeaderRow ) {
188190
// should skip header row
189191
firstRowIndex++;
@@ -785,6 +787,14 @@ private List<List<Object>> readRows( ZipFile zipFile, String sheetName, int firs
785787
if( columnIndex > 0 ) { // ensures that cell ref is valid
786788
columnIndex -= sheetDimension.getFirstColumnIndex();
787789
if( columnIndex >= 0 && columnIndex < columnCount ) {
790+
ValueType columnType = sheetNamesToColumnTypes.get( sheetName ).get( columnIndex );
791+
if( value instanceof String && columnType == ValueType.NUMBER ) {
792+
try {
793+
value = Double.valueOf( (String)value );
794+
} catch( Exception ex ) {
795+
// fallback to string value
796+
}
797+
}
788798
row.set( columnIndex, value );
789799
}
790800
}

test/com/inet/excel/parser/ExcelParserTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,16 @@ public void values_representing_date_or_time_are_provided_as_instances_of_time_o
340340
assertEquals( asList( asList( time, time, time, time ) ), parser.getRows( sheetName, 10, 10 ) );
341341
}
342342

343+
@Test
344+
public void values_representing_numbers_are_provided_as_instances_of_double() {
345+
File resource = new File( ExcelParserTest.class.getResource( "./files/numbers.xlsx" ).getPath() );
346+
ExcelParser parser = new ExcelParser( resource.toPath(), false );
347+
348+
List<Object> expectedRow = asList( Double.valueOf( 123 ), Double.valueOf( 456 ), Double.valueOf( 789 ), Double.valueOf( 321 ), Double.valueOf( 55 ), Double.valueOf( 33 ), Double.valueOf( 10 ) );
349+
350+
assertEquals( asList( expectedRow ), parser.getRows( "Sheet1", 1, 1 ) );
351+
}
352+
343353
@Test
344354
public void getColumnTypes_throws_exception_if_excel_file_does_not_exist() {
345355
method_throws_exception_if_excel_file_does_not_exist( parser -> parser.getColumnTypes( "sheetName" ) );
8.14 KB
Binary file not shown.

0 commit comments

Comments
 (0)