Apache POI Excel getDateCellValue() wrong year

2019-07-23 16:50发布

问题:

I am using Apache POI to read several Excel files and convert them to an Oracle DB. My code looks roughly like this:

wb = new HSSFWorkbook( new FileInputStream( FORECAST_HEADER_EXCEL_FILE ) );
Sheet sheet = wb.getSheetAt( 0 );
int rows = sheet.getPhysicalNumberOfRows();

// For each row...
for ( int r = 0; r < rows; r++ ) {
    Row row = sheet.getRow( r );
    ForecastLine forecastLine = new ForecastLine();

    cell = row.getCell( EXCEL_COLUMN_BUCKET_START );
    forecastLine.setBucketStart( cell == null 
        ? null 
        : cell.getDateCellValue() );

}

With two of the sheets (separate files) my dates come out fine, but with one the year is wrong (1900, as if there were no year). The columns seems formatted the same in Excel. I've tried different Excel formats on the dates to see if POI would parse them correctly, but no. I don't know if there's a way to affect the POI date parser. Any ideas?