我使用的Apache POI庫來讀取Excel文件。我在閱讀密碼單元時被卡住了。如果用戶在密碼單元格中輸入日期,例如16/05/2012。我將此值讀作「41045」,而值應該是「16/05/2012」。這是我的代碼:閱讀日期值作爲字符串
cell = row.getCell(); // date in the cell password '16/05/2012'
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if(cellCount == TEMPLATE_PASSWORD) {// if cell is password
cell.setCellType(Cell.CELL_TYPE_STRING);
cellValue = cell.getRichStringCellValue().getString(); // value read is 41045 and not "16/05/2012"
}
break;
default:
}
任何人都可以幫忙嗎?
謝謝。
看看這個線程,它幾乎與你的問題相同。 http://stackoverflow.com/questions/3148535/how-to-read-excel-cell-having-date-with-apache-poi – 2012-05-16 10:49:57
@mashhur在你的鏈接,沒有按照我的要求沒有解決方案。 –
我認爲你收到的是數字而不是字符串,因爲單元格的類型是數字。你確定數字類型對密碼單元格是否正確? – ImLearning