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


Java FormulaError类代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.FormulaError的典型用法代码示例。如果您正苦于以下问题:Java FormulaError类的具体用法?Java FormulaError怎么用?Java FormulaError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FormulaError类属于org.apache.poi.ss.usermodel包,在下文中一共展示了FormulaError类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getErrorCellValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
/**
 * エラーセルの値を評価する。
 * @since 0.8.3
 * @param errorValue エラーセルの値。
 * @param locale
 * @return
 */
private CellFormatResult getErrorCellValue(final byte errorValue, final Locale locale) {
    
   final FormulaError error = FormulaError.forInt(errorValue);
   final CellFormatResult result = new CellFormatResult();
   result.setCellType(FormatCellType.Error);
   result.setValue(error.getCode());
   
   if(isErrorCellAsEmpty()) {
       result.setText("");
   } else {
       result.setText(error.getString());
   }
   
   return result;
   
}
 
开发者ID:mygreen,项目名称:excel-cellformatter,代码行数:24,代码来源:POICellFormatter.java

示例2: visitCellValueError

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
protected void visitCellValueError(PoiExcelColumnBean bean, Object cell, int errorCode, CellVisitor visitor) {
	Column column = bean.getColumn();

	ErrorStrategy strategy = bean.getCellErrorStrategy();
	switch (strategy.getStrategy()) {
	default:
		pageBuilder.setNull(column);
		return;
	case CONSTANT:
		String value = strategy.getValue();
		if (value == null) {
			pageBuilder.setNull(column);
		} else {
			visitor.visitCellValueString(column, cell, value);
		}
		return;
	case ERROR_CODE:
		break;
	case EXCEPTION:
		FormulaError error = FormulaError.forInt((byte) errorCode);
		throw new RuntimeException(MessageFormat.format("encount cell error. error_code={0}({1})", errorCode,
				error.getString()));
	}

	visitor.visitCellValueError(column, cell, errorCode);
}
 
开发者ID:hishidama,项目名称:embulk-parser-poi_excel,代码行数:27,代码来源:PoiExcelCellValueVisitor.java

示例3: testCellError_code

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
@Theory
public void testCellError_code(String excelFile) throws Exception {
	try (EmbulkPluginTester tester = new EmbulkPluginTester()) {
		tester.addParserPlugin(PoiExcelParserPlugin.TYPE, PoiExcelParserPlugin.class);

		EmbulkTestParserConfig parser = tester.newParserConfig(PoiExcelParserPlugin.TYPE);
		parser.set("sheet", "test1");
		parser.set("skip_header_lines", 7);
		parser.set("on_cell_error", "error_code");
		parser.addColumn("b", "boolean").set("column_number", "A");
		parser.addColumn("l", "long").set("column_number", "A");
		parser.addColumn("d", "double").set("column_number", "A");
		parser.addColumn("s", "string").set("column_number", "A");

		URL inFile = getClass().getResource(excelFile);
		List<OutputRecord> result = tester.runParser(inFile, parser);

		OutputRecord r = result.get(0);
		assertThat(r.getAsBoolean("b"), is(nullValue()));
		assertThat(r.getAsLong("l"), is((long) FormulaError.DIV0.getCode()));
		assertThat(r.getAsDouble("d"), is((double) FormulaError.DIV0.getCode()));
		assertThat(r.getAsString("s"), is("#DIV/0!"));
	}
}
 
开发者ID:hishidama,项目名称:embulk-parser-poi_excel,代码行数:25,代码来源:TestPoiExcelParserPlugin_cellError.java

示例4: updatePrecalculatedCellValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
private boolean updatePrecalculatedCellValue(Cell destination, CellValue val) {
  if(val != null) {
    switch(val.getCellType()) {
    case Cell.CELL_TYPE_BOOLEAN:
      return updatePrecalculatedBoolean(destination, val.getBooleanValue());
    case Cell.CELL_TYPE_NUMERIC:
      return updatePrecalculatedNumeric(destination, val.getNumberValue());
    case Cell.CELL_TYPE_STRING:
      return updatePrecalculatedString(destination, val.getStringValue());
    case Cell.CELL_TYPE_BLANK:
      return updatePrecalculatedBlank(destination);
    case Cell.CELL_TYPE_ERROR:
      return updatePrecalculatedError(destination,
          FormulaError.forInt(val.getErrorValue()));
    default: return false;
    }
  } else {
    return updatePrecalculatedError(destination, FormulaError.REF);
  }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:21,代码来源:SpreadsheetDataSource.java

示例5: formatCellValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
/**
 * <p>
 * Returns the formatted value of a cell as a <tt>String</tt> regardless
 * of the cell type. If the Excel format pattern cannot be parsed then the
 * cell value will be formatted using a default format.
 * </p>
 * <p>When passed a null or blank cell, this method will return an empty
 * String (""). Formula cells will be evaluated using the given
 * {@link FormulaEvaluator} if the evaluator is non-null. If the
 * evaluator is null, then the formula String will be returned. The caller
 * is responsible for setting the currentRow on the evaluator
 *</p>
 *
 * @param cell The cell (can be null)
 * @param evaluator The FormulaEvaluator (can be null)
 * @return a string value of the cell
 */
public String formatCellValue(Cell cell, FormulaEvaluator evaluator) {
    localeChangedObervable.checkForLocaleChange();
    
    if (cell == null) {
        return "";
    }

    int cellType = cell.getCellType();
    if (cellType == Cell.CELL_TYPE_FORMULA) {
        if (evaluator == null) {
            return cell.getCellFormula();
        }
        cellType = evaluator.evaluateFormulaCell(cell);
    }
    switch (cellType) {
        case Cell.CELL_TYPE_NUMERIC :

            if (ExcelDateUtil.isCellDateFormatted(cell)) {
                return getFormattedDateString(cell);
            }
            return getFormattedNumberString(cell);

        case Cell.CELL_TYPE_STRING :
            return cell.getRichStringCellValue().getString();

        case Cell.CELL_TYPE_BOOLEAN :
            return String.valueOf(cell.getBooleanCellValue());
        case Cell.CELL_TYPE_BLANK :
            return "";
        case Cell.CELL_TYPE_ERROR:
        	return FormulaError.forInt(cell.getErrorCellValue()).getString();
    }
    throw new RuntimeException("Unexpected celltype (" + cellType + ")");
}
 
开发者ID:bingyulei007,项目名称:bingexcel,代码行数:52,代码来源:ExcelDataFormatter.java

示例6: updatePrecalculatedValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
private boolean updatePrecalculatedValue(Cell destination,
    Cell source, FormulaEvaluator sEvaluator) {
  if(source != null) {
    switch(source.getCellType()) {
    case Cell.CELL_TYPE_BLANK:
      return updatePrecalculatedBlank(destination);
    case Cell.CELL_TYPE_BOOLEAN:
      return updatePrecalculatedBoolean(destination, source.getBooleanCellValue());
    case Cell.CELL_TYPE_ERROR:
      return updatePrecalculatedError(destination,
          FormulaError.forInt(source.getErrorCellValue()));
    case Cell.CELL_TYPE_FORMULA:
      try {
        return updatePrecalculatedCellValue(destination, sEvaluator.evaluate(source));
      } catch(Exception e) {
        switch(source.getCachedFormulaResultType()) {
        case Cell.CELL_TYPE_NUMERIC:
          return updatePrecalculatedNumeric(destination, source.getNumericCellValue());
        case Cell.CELL_TYPE_STRING:
          return updatePrecalculatedString(destination, source.getStringCellValue());
        case Cell.CELL_TYPE_BOOLEAN:
          return updatePrecalculatedBoolean(destination, source.getBooleanCellValue());
        case Cell.CELL_TYPE_ERROR:
          return updatePrecalculatedError(destination,
              FormulaError.forInt(source.getErrorCellValue()));
        }
      }
    case Cell.CELL_TYPE_NUMERIC:
      return updatePrecalculatedNumeric(destination, source.getNumericCellValue());
    case Cell.CELL_TYPE_STRING:
      return updatePrecalculatedString(destination, source.getStringCellValue());
    default:
      return false;
    }
  } else {
    return updatePrecalculatedError(destination, FormulaError.REF);
  }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:39,代码来源:SpreadsheetDataSource.java

示例7: updatePrecalculatedError

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
private boolean updatePrecalculatedError(Cell destination, FormulaError sError) {
  if(isFormula(destination)) {
    try {
      FormulaError dError = FormulaError.forInt(destination.getErrorCellValue());
      if(sError != dError) {
        destination.setCellErrorValue(sError.getCode());
        return true;
      }
    } catch(Exception e) {
      destination.setCellErrorValue(sError.getCode());
      return true;
    }
  }
  return false;
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:16,代码来源:SpreadsheetDataSource.java

示例8: getErrorCellValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
public int getErrorCellValue() {
    if (CELL_TYPE_ERROR != ConverterUtils.resolveCellType(this.value)) { throw new CalculationEngineException("Trying to get error value from non-error cell."); }
    return FormulaError.forString((String) this.value.get()).getCode();
}
 
开发者ID:DataArt,项目名称:CalculationEngine,代码行数:5,代码来源:PoiWorkbookConverters.java

示例9: visitCellValueError

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
@Override
public void visitCellValueError(Column column, Object source, int code) {
	FormulaError error = FormulaError.forInt((byte) code);
	String value = error.getString();
	pageBuilder.setString(column, value);
}
 
开发者ID:hishidama,项目名称:embulk-parser-poi_excel,代码行数:7,代码来源:StringCellVisitor.java

示例10: getCellValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
public static String getCellValue(Workbook wb, Cell cell) {
    if (cell == null) {
        return null;
    }

    final String cellCoordinate = "(" + cell.getRowIndex() + "," + cell.getColumnIndex() + ")";

    final String result;

    switch (cell.getCellTypeEnum()) {
    case BLANK:
    case _NONE:
        result = null;
        break;
    case BOOLEAN:
        result = Boolean.toString(cell.getBooleanCellValue());
        break;
    case ERROR:
        String errorResult;
        try {
            byte errorCode = cell.getErrorCellValue();
            FormulaError formulaError = FormulaError.forInt(errorCode);
            errorResult = formulaError.getString();
        } catch (RuntimeException e) {
            logger.debug("Getting error code for {} failed!: {}", cellCoordinate, e.getMessage());
            if (cell instanceof XSSFCell) {
                // hack to get error string, which is available
                String value = ((XSSFCell) cell).getErrorCellString();
                errorResult = value;
            } else {
                logger.error("Couldn't handle unexpected error scenario in cell: " + cellCoordinate, e);
                throw e;
            }
        }
        result = errorResult;
        break;
    case FORMULA:
        // result = cell.getCellFormula();
        result = getFormulaCellValue(wb, cell);
        break;
    case NUMERIC:
        if (HSSFDateUtil.isCellDateFormatted(cell)) {
            Date date = cell.getDateCellValue();
            if (date == null) {
                result = null;
            } else {
                result = DateUtils.createDateFormat().format(date);
            }
        } else {
            // TODO: Consider not formatting it, but simple using
            // Double.toString(...)
            result = _numberFormat.format(cell.getNumericCellValue());
        }
        break;
    case STRING:
        result = cell.getRichStringCellValue().getString();
        break;
    default:
        throw new IllegalStateException("Unknown cell type: " + cell.getCellTypeEnum());
    }

    logger.debug("cell {} resolved to value: {}", cellCoordinate, result);

    return result;
}
 
开发者ID:apache,项目名称:metamodel,代码行数:66,代码来源:ExcelUtils.java

示例11: getCellValue

import org.apache.poi.ss.usermodel.FormulaError; //导入依赖的package包/类
private CellData getCellValue(CellData cellData) 
{

	//CellData cellData = new CellData();

	if(cellData.cell != null)
	{
	// evaluator.evaluateFormulaCell(cell);

	int cellTypeEvaluator = cellData.workBookObject.evaluator.evaluateFormulaCell(cellData.cell);

	int cellType = cellTypeEvaluator > -1 ? cellTypeEvaluator : cellData.cell
			.getCellType();

	switch (cellType)
	{

	case Cell.CELL_TYPE_BLANK:

		// cellData.put("type",HSSFCell.CELL_TYPE_BLANK);
		cellData.value = cellData.cell.getStringCellValue();
		
		break;

	case Cell.CELL_TYPE_NUMERIC:

		// cellData.put("type",HSSFCell.CELL_TYPE_NUMERIC);
		cellData.value = Double.toString(cellData.cell.getNumericCellValue());

		break;

	case Cell.CELL_TYPE_STRING:

		// cellData.put("type",HSSFCell.CELL_TYPE_STRING);
		cellData.value = cellData.cell.getStringCellValue();

		break;

	case Cell.CELL_TYPE_ERROR:

		cellData.error = FormulaError.forInt(cellData.cell.getErrorCellValue()).name();
		cellData.value = "ERROR";

		break;

	case Cell.CELL_TYPE_FORMULA:

		// cellData.put("type", HSSFCell.CELL_TYPE_ERROR);
		cellData.value = cellData.cell.getCellFormula();

		break;

	default:

		// cellData.put("type",HSSFCell.CELL_TYPE_STRING);
		cellData.value = cellData.cell.getCellStyle().getDataFormatString();

	}

	// si la celda es pocentaje multiplico por 100

	if (cellData.cell.getCellStyle().getDataFormatString().contains("%")
			&& cellType == Cell.CELL_TYPE_NUMERIC)
	{

		Double perceValue = Double.parseDouble(cellData.value) * 100;
		cellData.value = perceValue.toString();

	}

	}
	else
	{
		cellData.value = null;
		
	}

	
	return cellData;
}
 
开发者ID:rodrigoEclipsa,项目名称:excelToApp,代码行数:81,代码来源:ExcelBase.java


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