当前位置: 首页>>代码示例>>Java>>正文


Java HSSFCell.getStringCellValue方法代码示例

本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.getStringCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.getStringCellValue方法的具体用法?Java HSSFCell.getStringCellValue怎么用?Java HSSFCell.getStringCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.hssf.usermodel.HSSFCell的用法示例。


在下文中一共展示了HSSFCell.getStringCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCellValue

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String getCellValue(HSSFCell cell){
	if(cell == null) return "";
	
	switch (cell.getCellType()) {
	case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue();
	case HSSFCell.CELL_TYPE_BOOLEAN : return Boolean.toString(cell.getBooleanCellValue());
	case HSSFCell.CELL_TYPE_NUMERIC : 
		if(HSSFDateUtil.isCellDateFormatted(cell))
			return DateUtils.formatDateTime("yyyyMMdd", HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
		else
			return new BigDecimal(cell.getNumericCellValue()).toPlainString();
	case HSSFCell.CELL_TYPE_FORMULA : return "";
	case HSSFCell.CELL_TYPE_BLANK : return "";
	default:return "";
	}
}
 
开发者ID:ken8271,项目名称:parrot,代码行数:17,代码来源:XlsParser.java

示例2: getCellValue

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
 * 获取EXCEL文件单元列值
 * 
 * @param row
 * @param point
 * @return
 */
private static String getCellValue(HSSFRow row, int point) {
	String reString = "";
	try {
		HSSFCell cell = row.getCell((short) point);
		if (cell.getCellType() == 1)
			reString = cell.getStringCellValue();
		else if (cell.getCellType() == 0) {
			reString = convert(cell.getNumericCellValue());
			BigDecimal bd = new BigDecimal(reString);
			reString = bd.toPlainString();
		} else {
			reString = "";
		}
		System.out.println(cell.getCellType() + ":" + cell.getCellFormula());
	} catch (Exception localException) {
	}
	return checkNull(reString);
}
 
开发者ID:fellyvon,项目名称:wasexport,代码行数:26,代码来源:ExcelUtil.java

示例3: parseBooleanCell

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private boolean parseBooleanCell(HSSFCell cell) {
if (cell != null) {
    String value;
    try {
	cell.setCellType(Cell.CELL_TYPE_STRING);
	if (cell.getStringCellValue() != null) {
	    if (cell.getStringCellValue().trim().length() != 0) {
		emptyRow = false;
	    }
	} else {
	    return false;
	}
	value = cell.getStringCellValue().trim();
    } catch (Exception e) {
	cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	double d = cell.getNumericCellValue();
	emptyRow = false;
	value = new Long(new Double(d).longValue()).toString();
    }
    if (StringUtils.equals(value, "1") || StringUtils.equalsIgnoreCase(value, "true")) {
	return true;
    }
}
return false;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:ImportService.java

示例4: parseStringCell

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String parseStringCell(HSSFCell cell) {
if (cell != null) {
    try {
	cell.setCellType(Cell.CELL_TYPE_STRING);
	if (cell.getStringCellValue() != null) {
	    if (cell.getStringCellValue().trim().length() != 0) {
		emptyRow = false;
	    }
	} else {
	    return null;
	}
	// log.debug("string cell value: '"+cell.getStringCellValue().trim()+"'");
	return cell.getStringCellValue().trim();
    } catch (Exception e) {
	cell.setCellType(Cell.CELL_TYPE_NUMERIC);
	double d = cell.getNumericCellValue();
	emptyRow = false;
	// log.debug("numeric cell value: '"+d+"'");
	return (new Long(new Double(d).longValue()).toString());
    }
}
return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:ImportService.java

示例5: WorkbookReader

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
 * Constructor.
 *
 * @param xlsFileName
 *          the file name of the xls to read
 */
public WorkbookReader(final String xlsFileName) {
  super(xlsFileName);

  HSSFRow firstRow = sheet.getRow(rowNumber++);

  int columnNumber = COLUMN_DEFAULT_LANG + 1;
  HSSFCell cell = null;
  while (((cell = firstRow.getCell(columnNumber)) != null)) {
    if (!cell.getStringCellValue().trim().isEmpty()) {
      String lang = cell.getStringCellValue();
      langColumnNumber.put(lang, columnNumber);
      columnNumber++;
    }
  }

}
 
开发者ID:everit-org,项目名称:i18n-props-xls-converter,代码行数:23,代码来源:WorkbookReader.java

示例6: getNextRow

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
 * Get next row in the sheet. Read rows between second to last row.
 *
 * @return the {@link WorkbookRowDTO}.
 */
public WorkbookRowDTO getNextRow() {
  if (sheet == null) {
    throw new RuntimeException("Not opened workbook yet.");
  }

  HSSFRow row = sheet.getRow(rowNumber++);
  HSSFCell propertiesFileNameCell = row.getCell(COLUMN_PROPERTIES_FILE_NAME);
  String propertiesFileName = propertiesFileNameCell.getStringCellValue();

  HSSFCell propKeyCell = row.getCell(COLUMN_PROPERTY_KEY);
  HSSFCell defaultLangCell = row.getCell(COLUMN_DEFAULT_LANG);
  HashMap<String, String> langValues = new HashMap<String, String>();

  langColumnNumber.forEach((key, value) -> {
    HSSFCell langCell = row.getCell(value);
    String langValue = langCell == null ? "" : langCell.getStringCellValue();
    langValues.put(key, langValue);
  });

  return new WorkbookRowDTO()
      .propertiesFile(propertiesFileName)
      .propKey(propKeyCell.getStringCellValue())
      .defaultLangValue(defaultLangCell.getStringCellValue())
      .langValues(langValues);
}
 
开发者ID:everit-org,项目名称:i18n-props-xls-converter,代码行数:31,代码来源:WorkbookReader.java

示例7: fromHSSFRowtoCSV

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String fromHSSFRowtoCSV(HSSFRow row){
    StringBuffer csvRow = new StringBuffer();
    int l = row.getLastCellNum();
    for (int i=0;i<l;i++){
        HSSFCell cell = row.getCell((short)i);
        String cellValue = "";
        if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
            cellValue = "";
        } else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
            cellValue = "\"" + cell.getStringCellValue() + "\"";
        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
            double value = cell.getNumericCellValue();
            cellValue = getNumberFormat().format(value);
            cellValue = "\"" + cellValue + "\"";
        }

        csvRow.append(cellValue);

        if (i<l){
            csvRow.append(getCsvDelimiter().toCharArray()[0]);
        }
    }
    return csvRow.toString();

}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:26,代码来源:SpreadsheetUploadBean.java

示例8: getStringValueOfCell

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String getStringValueOfCell(HSSFCell cell, int cellType) {
	
	switch (cellType) {

	case Cell.CELL_TYPE_BOOLEAN:
		return cell.getBooleanCellValue() ? "Ja" : "Nein";

	case Cell.CELL_TYPE_FORMULA:
		return getStringValueOfCell(cell, cell.getCachedFormulaResultType());

	case Cell.CELL_TYPE_NUMERIC:
		double number = cell.getNumericCellValue();
		if(Double.isInfinite(number) || Double.isNaN(number) || Math.floor(number) != number)
			return Double.toString(number);
		else
			return String.valueOf(new Double(number).intValue());

	case Cell.CELL_TYPE_STRING:
		return cell.getStringCellValue();
		
	}
	AtomTools.log(Level.SEVERE, "unknown celltype: " + cellType + "; content of cell = " + cell.toString(), this);
	return null;
	
}
 
开发者ID:fhcampuswien,项目名称:atom,代码行数:26,代码来源:UploadImportServlet.java

示例9: manageInteger

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Integer manageInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
	Integer result = null;
	if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
	} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
		if (cell.getStringCellValue().trim().length() > 0) {
			result = new Integer(cell.getStringCellValue());
			if (ps != null) ps.setInt(lfdCol, result);
			if (psUpdate != null) psUpdate.setInt(lfdCol, result);
			return result;
		}
	} else {
		result = new Integer((int) cell.getNumericCellValue());
		if (ps != null) ps.setInt(lfdCol, result);
		if (psUpdate != null) psUpdate.setInt(lfdCol, result);
		return result;
	}
	if (ps != null) ps.setNull(lfdCol, java.sql.Types.INTEGER);
	if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.INTEGER);
	return result;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:21,代码来源:GeneralXLSImporter.java

示例10: manageBigInteger

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Long manageBigInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
	Long result = null;
	if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
	} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
		if (cell.getStringCellValue().trim().length() > 0) {
			result = new Long(cell.getStringCellValue());
			if (ps != null) ps.setLong(lfdCol, result);
			if (psUpdate != null) psUpdate.setLong(lfdCol, result);
			return result;
		}
	} else {
		result = new Long((long) cell.getNumericCellValue());
		if (ps != null) ps.setLong(lfdCol, result);
		if (psUpdate != null) psUpdate.setLong(lfdCol, result);
		return result;
	}
	if (ps != null) ps.setNull(lfdCol, java.sql.Types.BIGINT);
	if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BIGINT);
	return result;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:21,代码来源:GeneralXLSImporter.java

示例11: parseStringCell

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String parseStringCell(HSSFCell cell) {
if (cell != null) {
    cell.setCellType(Cell.CELL_TYPE_STRING);
    if (cell.getStringCellValue() != null) {
	return cell.getStringCellValue().trim();
    }
}
return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:GroupingUploadAJAXAction.java

示例12: getCellStringValue

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static String getCellStringValue(HSSFCell cell) {
	String cellValue = "";
	switch (cell.getCellType()) {
	case HSSFCell.CELL_TYPE_STRING:
		cellValue = cell.getStringCellValue();
		if (cellValue.trim().equals("") || cellValue.trim().length() <= 0) {
			cellValue = " ";
		}
		break;
	case HSSFCell.CELL_TYPE_NUMERIC:
		// cellValue = String.valueOf(cell.getNumericCellValue());
		DecimalFormat formatter = new DecimalFormat("######");
		cellValue = formatter.format(cell.getNumericCellValue());
		break;
	case HSSFCell.CELL_TYPE_FORMULA:
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		cellValue = String.valueOf(cell.getNumericCellValue());
		break;
	case HSSFCell.CELL_TYPE_BLANK:
		cellValue = " ";
		break;
	case HSSFCell.CELL_TYPE_BOOLEAN:
		break;
	case HSSFCell.CELL_TYPE_ERROR:
		break;
	default:
		break;
	}
	return cellValue;
}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:31,代码来源:ReadExcelUtil.java

示例13: getStringVal

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String getStringVal(HSSFCell cell){
	String value="";
	if(cell != null) {
		switch (cell.getCellTypeEnum()) {

			case FORMULA:
				value =  cell.getCellFormula();
				break;

			case NUMERIC:
				value = String.valueOf(new DecimalFormat("#").format(cell.getNumericCellValue()));
				break;

			case STRING:
				value = cell.getStringCellValue();
				break;

			case BLANK:
				value ="";
				break;

			case BOOLEAN:
				value =	String.valueOf(cell.getBooleanCellValue());
				break;

			case ERROR:
				value =	String.valueOf(cell.getErrorCellValue());
				break;

			default:
				value =	String.valueOf(cell.getCellTypeEnum());
		}
		
	}
	return value;
}
 
开发者ID:gyp220203,项目名称:renren-msg,代码行数:37,代码来源:ParseExcelServiceImpl.java

示例14: get

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public String get(int sheetIndex, int x_index, int y_index) {
    String str = "";
    try {
        if (wb == null) throw new Exception("未打开文件");
        HSSFCell cell = wb.getSheetAt(sheetIndex).getRow(x_index).getCell(y_index);
        cell.setCellType(Cell.CELL_TYPE_STRING);//处理读取xls时 单元格使用各类函数的数据读取问题
        str = cell.getStringCellValue();
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    return str;
}
 
开发者ID:BetaSummer,项目名称:sztw,代码行数:13,代码来源:HSSF.java

示例15: openFile

import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public void openFile(File f) throws ReadException {
	trace.trace("Reading "+ f.getAbsolutePath());
	//If the file is existing, open and read it
	try {
		FileInputStream fin = new FileInputStream(f);
		POIFSFileSystem poifs = new POIFSFileSystem(fin);
		wb = new HSSFWorkbook(poifs);
	} catch (IOException e) {
		throw new ReadException("Error while trying to read file "+f.getAbsolutePath(), e);
	}
	currentSheet = wb.getSheet(sheetName);
	//If we do not have a sheet with the given name, throw exception.
	if (currentSheet == null)
		throw new ReadException("No sheet with name "+sheetName+" found in file "+f.getAbsolutePath(), null);
	nextRowNumber = currentSheet.getFirstRowNum();
	
	//If we have a aheader row, read it to get the actual schema
	if (hasHeader){
		if (useHeaderNames){
			HSSFRow row = currentSheet.getRow(nextRowNumber);
			//Last cell num is zero based => +1
			String[] fields = new String[row.getLastCellNum()];
			trace.trace("Number of fields:"+fields.length);
			Iterator<Cell> iter = row.cellIterator();
			while (iter.hasNext()) {
				HSSFCell element = (HSSFCell) iter.next();
				String value = element.getStringCellValue();
				fields[element.getCellNum()]=value;
			}
			//We might have some nulls in the array. Default them.
			for (int i = 0; i < fields.length; i++) {
				String string = fields[i];
				if (string==null)
					fields[i]="_Unknown_"+i+"_";
			}
			schema = fields;
			nextRowNumber++;
		}
	}
}
 
开发者ID:scauwe,项目名称:Generic-File-Driver-for-IDM,代码行数:41,代码来源:XlsFileReader.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFCell.getStringCellValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。