List of usage examples for org.apache.poi.ss.usermodel DataFormatter createFormat
public Format createFormat(Cell cell)
From source file:org.testeditor.core.importer.ExcelFileImporter.java
License:Open Source License
/** * gets the testData from a numeric cell. * /* w ww .java 2 s . c o m*/ * @param testDataRow * TestDataRow * @param cell * HSSFCell */ protected void getTestDataNumericCell(TestDataRow testDataRow, HSSFCell cell) { if (HSSFDateUtil.isCellDateFormatted(cell)) { double value = cell.getNumericCellValue(); if (HSSFDateUtil.isValidExcelDate(value)) { Date date = HSSFDateUtil.getJavaDate(cell.getNumericCellValue()); DateFormat format = new SimpleDateFormat(JAVA_TOSTRING); testDataRow.add(format.format(date)); } } else { DataFormatter df = new DataFormatter(); Format cellFormat = df.createFormat(cell); if (cellFormat instanceof DecimalFormat) { String pattern = ((DecimalFormat) cellFormat).toPattern(); DecimalFormat dFormatter = new DecimalFormat(pattern); testDataRow.add(dFormatter.format(cell.getNumericCellValue())); } else { testDataRow.add(String.valueOf(cell.getNumericCellValue())); } } }