All Downloads are FREE. Search and download functionalities are using the official Maven repository.

holmos.webtest.junitextentions.parameters.excel.HolmosCell Maven / Gradle / Ivy

There is a newer version: 1.0.2u10
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy