stop = true; } else { if ( cell.getType() != KCellType.EMPTY ) { if ( below.getType() == KCellType.BOOLEAN ) { fieldtype = ValueMetaInterface.TYPE_BOOLEAN; } else if ( below.getType() == KCellType.DATE ) { fieldtype = ValueMetaInterface.TYPE_DATE; } else if ( below.getType() == KCellType.LABEL ) { fieldtype = ValueMetaInterface.TYPE_STRING; } else if ( below.getType() == KCellType.NUMBER ) { fieldtype = ValueMetaInterface.TYPE_NUMBER; } else {
@Test public void testReadCells() throws Exception { KSheet sheet = getSampleSheet(); KCell cell = sheet.getCell( 1, 2 ); assertEquals( "One", cell.getValue() ); assertEquals( KCellType.LABEL, cell.getType() ); cell = sheet.getCell( 2, 2 ); assertEquals( KCellType.DATE, cell.getType() ); assertEquals( new Date( 1283817600000L ), cell.getValue() ); cell = sheet.getCell( 1, 3 ); assertEquals( "Two", cell.getValue() ); assertEquals( KCellType.LABEL, cell.getType() ); }
@Test public void testNullDateCell() throws Exception { // cell had null value instead of being null final String sheetId = "1"; final String sheetName = "Sheet 1"; XSSFReader reader = mockXSSFReader( sheetId, SHEET_DATE_NO_V, mockSharedStringsTable( "Some Date" ), mockStylesTable( Collections.singletonMap( 2, 165 ), Collections.singletonMap( 165, "M/D/YYYY" ) ) ); StaxPoiSheet spSheet = spy( new StaxPoiSheet( reader, sheetName, sheetId ) ); doReturn( true ).when( spSheet ).isDateCell( any() ); KCell cell = spSheet.getRow( 1 )[ 0 ]; assertNotNull( cell ); assertEquals( KCellType.DATE, cell.getType() ); cell = spSheet.getRow( 2 )[ 0 ]; assertNull( "cell must be null", cell ); }
@Test public void testInlineString() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; XSSFReader reader = mockXSSFReader( sheetId, SHEET_INLINE_STRINGS, mock( SharedStringsTable.class ), mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); KCell[] rowCells = spSheet.getRow( 0 ); assertEquals( "Test1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "Test2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 1 ); assertEquals( "value 1 1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); rowCells = spSheet.getRow( 2 ); assertEquals( "value 1 2", rowCells[ 0 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 0 ].getType() ); assertEquals( "value 2 2", rowCells[ 1 ].getValue() ); assertEquals( KCellType.STRING_FORMULA, rowCells[ 1 ].getType() ); }
assertEquals( KCellType.LABEL, row[ 1 ].getType() ); assertEquals( "One", row[ 1 ].getValue() ); assertEquals( KCellType.DATE, row[ 2 ].getType() ); assertEquals( new Date( 1283817600000L ), row[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, row[ 3 ].getType() ); assertEquals( Double.valueOf( "75" ), row[ 3 ].getValue() ); assertEquals( KCellType.BOOLEAN, row[ 4 ].getType() ); assertEquals( Boolean.TRUE, row[ 4 ].getValue() ); assertEquals( KCellType.NUMBER_FORMULA, row[ 5 ].getType() ); assertEquals( Double.valueOf( "75" ), row[ 5 ].getValue() ); assertEquals( KCellType.LABEL, row[ 1 ].getType() ); assertEquals( "Two", row[ 1 ].getValue() ); assertEquals( KCellType.DATE, row[ 2 ].getType() ); assertEquals( new Date( 1283904000000L ), row[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, row[ 3 ].getType() ); assertEquals( Double.valueOf( "42" ), row[ 3 ].getValue() ); assertEquals( KCellType.BOOLEAN, row[ 4 ].getType() ); assertEquals( Boolean.FALSE, row[ 4 ].getValue() ); assertEquals( KCellType.NUMBER_FORMULA, row[ 5 ].getType() ); assertEquals( Double.valueOf( "117" ), row[ 5 ].getValue() ); assertEquals( KCellType.LABEL, row[ 1 ].getType() ); assertEquals( "Three", row[ 1 ].getValue() ); assertEquals( KCellType.DATE, row[ 2 ].getType() ); assertEquals( new Date( 1283990400000L ), row[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, row[ 3 ].getType() ); assertEquals( Double.valueOf( "93" ), row[ 3 ].getValue() ); assertEquals( KCellType.BOOLEAN, row[ 4 ].getType() );
@Test public void testNoUsedRangeSpecified() throws Exception { final String sheetId = "1"; final String sheetName = "Sheet 1"; SharedStringsTable sharedStringsTableMock = mockSharedStringsTable( "Report ID", "Report ID", "Approval Status", "Total Report Amount", "Policy", "ReportIdValue_1", "ReportIdValue_1", "ApprovalStatusValue_1", "PolicyValue_1" ); XSSFReader reader = mockXSSFReader( sheetId, SHEET_NO_USED_RANGE_SPECIFIED, sharedStringsTableMock, mock( StylesTable.class ) ); StaxPoiSheet spSheet = new StaxPoiSheet( reader, sheetName, sheetId ); // The first row is empty - it should have empty rowCells KCell[] rowCells = spSheet.getRow( 0 ); assertEquals( 0, rowCells.length ); // The second row - is the header - just skip it rowCells = spSheet.getRow( 1 ); assertEquals( 0, rowCells.length ); // The row3 - is the first row with data - validating it rowCells = spSheet.getRow( 2 ); assertEquals( KCellType.LABEL, rowCells[ 0 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 0 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 1 ].getType() ); assertEquals( "ReportIdValue_1", rowCells[ 1 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 2 ].getType() ); assertEquals( "ApprovalStatusValue_1", rowCells[ 2 ].getValue() ); assertEquals( KCellType.NUMBER, rowCells[ 3 ].getType() ); assertEquals( 2623.0, rowCells[ 3 ].getValue() ); assertEquals( KCellType.LABEL, rowCells[ 4 ].getType() ); assertEquals( "PolicyValue_1", rowCells[ 4 ].getValue() ); }
KCellType cellType = cell.getType(); if ( KCellType.BOOLEAN == cellType || KCellType.BOOLEAN_FORMULA == cellType ) { r[rowcolumn] = cell.getValue(); } else { if ( log.isDetailed() ) { KCellType ct = cell.getType(); logDetailed( BaseMessages.getString( PKG, "ExcelInput.Log.UnknownType", ( ( ct != null ) ? ct .toString() : "null" ), cell.getContents() ) );