schoolproject에 대한 testdate를 열어야합니다. 이 테스트 날짜는 숫자, 문자, 날짜 및 시간을 포함하는 Excel (xlsx) 파일입니다. 하지만 아래의 코드는 Excel 파일을 읽지 만 42538.0 및 1.153481443E9과 같은 이상한 숫자가 표시됩니다. 이후. 소수가 후 엑셀Apoche POI를 사용하여 java에서 excel (xlsx) 파일 읽기 (이상한 숫자 얻기)
public class Page4_Controller implements Initializable {
@FXML
private Button button1;
public void Button1Action(ActionEvent event) throws IOException {
//Initialize excel file
FileChooser fc = new FileChooser();
fc.getExtensionFilters().addAll(
new ExtensionFilter("Excel Files", "*.xlsx"));
File selectedFile = fc.showOpenDialog(null);
// Read file
readXLSXFile(selectedFile.getAbsolutePath());
}
public static void readXLSXFile(String excelFilePath) throws IOException {
FileInputStream fys = new FileInputStream(new File(excelFilePath));
//Create workbook instance that refers to .xlsx file
XSSFWorkbook wb = new XSSFWorkbook(fys);
//Create a sheet object to retrive the sheet
XSSFSheet sheet = wb.getSheetAt(0);
//That is for evalueate the cell type
FormulaEvaluator forlulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
DataFormatter df = new DataFormatter();
//Default data for database (comes later)
//String airport = sheet.getRow(1).getCell(1).getStringCellValue();
//Date date = sheet.getRow(2).getCell(1).getDateCellValue();
for (Row row : sheet) {
for (Cell cell : row) {
switch (forlulaEvaluator.evaluateInCell(cell).getCellType()) {
//If cell is a numeric format
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
System.out.print(df.formatCellValue(cell) + "\t");
break;
//If cell is a string format
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getRichStringCellValue() + "\t");
break;
}
}
System.out.println();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
42538.0은 날짜 (2016-06-17 00:00) 일 수 있습니다. 세포 유형이 DATE인지 확인해야합니다. – Stefan
날짜는 다음과 같이 작성됩니다. Date Found : 17-Jun-2016이며 셀 유형은 date입니다. –