Apache POI Excel getDateCellValue() wrong year

一笑奈何 提交于 2019-12-11 02:21:04

问题


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?

来源:https://stackoverflow.com/questions/16325983/apache-poi-excel-getdatecellvalue-wrong-year

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!