@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 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( "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( "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( "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() ); assertEquals( Boolean.TRUE, row[ 4 ].getValue() ); assertEquals( KCellType.NUMBER_FORMULA, row[ 5 ].getType() ); assertEquals( Double.valueOf( "210" ), row[ 5 ].getValue() );
@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() ); }
r[rowcolumn] = cell.getValue(); sourceMeta = data.valueMetaBoolean; } else { if ( KCellType.DATE.equals( cellType ) || KCellType.DATE_FORMULA.equals( cellType ) ) { Date date = (Date) cell.getValue(); long time = date.getTime(); int offset = TimeZone.getDefault().getOffset( time ); } else { if ( KCellType.LABEL == cellType || KCellType.STRING_FORMULA == cellType ) { String string = (String) cell.getValue(); switch ( meta.getField()[rowcolumn].getTrimType() ) { case ExcelInputMeta.TYPE_TRIM_LEFT: } else { if ( KCellType.NUMBER == cellType || KCellType.NUMBER_FORMULA == cellType ) { r[rowcolumn] = cell.getValue(); sourceMeta = data.valueMetaNumber; } else {