Skip to content

Instantly share code, notes, and snippets.

@koduki
Created January 16, 2011 08:48
Show Gist options
  • Save koduki/781657 to your computer and use it in GitHub Desktop.
Save koduki/781657 to your computer and use it in GitHub Desktop.
POI wrapper for scala
def getValue(cell:Cell):String = {
import Cell._
import org.apache.poi.ss.usermodel.DateUtil
if (cell == null) {
""
} else {
cell.getCellType match {
case CELL_TYPE_BLANK => ""
case CELL_TYPE_STRING => cell.getStringCellValue
case CELL_TYPE_NUMERIC => if (DateUtil.isCellDateFormatted(cell)) {
cell.getDateCellValue.getTime.toString
} else {
cell.getNumericCellValue.toString
}
case CELL_TYPE_FORMULA => cell.getNumericCellValue()
case CELL_TYPE_ERROR => cell.getErrorCellValue()
case CELL_TYPE_BOOLEAN => cell.getBooleanCellValue()
case _ => cell.toString
}
}.toString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment