天天看點

poi中Numeric的了解

有時候單元格輸入20121221的時間格式或者188888888的數字,讀取的時候都會被轉換為科學技術法方式的double類型,可我們想要的結果是以字元串的形式讀取到原來的值,在這裡可以使用String issuedate=NumberToTextConverter.toText(cell_10.getNumericCellValue());即org.apache.poi.ss.util.NumberToTextConverter;包下的NumberToTextConverter.toText()方法。即可解決。

還有一種情況就是輸入的2012-1-1,excel會将它視為Numeric類型,即日起類型類型是特殊的numeric類型,如果此時想要格式化該日期字元串該怎麼辦呢?

如下:

<span style="font-size:18px;">case Cell.CELL_TYPE_NUMERIC: {
			if(HSSFDateUtil.isCellDateFormatted(cell_11)){
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				tookdate= sdf.format(HSSFDateUtil.getJavaDate(cell_11.getNumericCellValue())).toString();
			}else{
				tookdate=NumberToTextConverter.toText(cell_11.getNumericCellValue());
				//System.out.println(">>>>>>>>>>>>>"+tookdate);
			}
			break;
		}</span>
           

比如我在單元格中輸入2012-1-1,則格式化後的字元串是2012-01-01