holmos.webtest.junitextentions.parameters.excel.HolmosCell Maven / Gradle / Ivy
package holmos.webtest.junitextentions.parameters.excel;
import org.apache.poi.ss.usermodel.Cell;
/**
* @author 吴银龙([email protected])
* */
public class HolmosCell {
private Cell cell;
public HolmosCell(Cell cell){
this.cell=cell;
}
public String getValueAsString(){
switch (cell.getCellType()) {
case Cell.CELL_TYPE_BLANK:
return null;
case Cell.CELL_TYPE_BOOLEAN:
return null;
case Cell.CELL_TYPE_ERROR:
return null;
case Cell.CELL_TYPE_FORMULA:
return null;
case Cell.CELL_TYPE_NUMERIC:
return Integer.toString((int) cell.getNumericCellValue());
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
default:
return null;
}
}
public int getValueAsInt(){
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
return (int) cell.getNumericCellValue();
case Cell.CELL_TYPE_STRING:
return Integer.parseInt(cell.getStringCellValue());
default: return 0;
}
}
public Object getValue(){
switch (cell.getCellType()) {
case Cell.CELL_TYPE_BLANK:
return null;
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case Cell.CELL_TYPE_ERROR:
return cell.getErrorCellValue();
case Cell.CELL_TYPE_FORMULA:
return cell.getNumericCellValue();
case Cell.CELL_TYPE_NUMERIC:
if(getValueAsString().contains("."))
return cell.getNumericCellValue();
else
return getValueAsInt();
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
default:
return null;
}
}
public void setIntValue(int value){
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellValue(value);
}
public void setStringValue(String value){
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue(value);
}
}