public static FormulaError ForString(String code) { FormulaError err = smap[code]; if (err == null) { throw new ArgumentException("Unknown error code: " + code); } return(err); }
public static FormulaError ForInt(byte type) { FormulaError err = imap[type]; if (err == null) { throw new ArgumentException("Unknown error type: " + type); } return(err); }
/** * * Returns the Formatted value of a cell as a <c>String</c> regardless * of the cell type. If the Excel FormatBase pattern cannot be Parsed then the * cell value will be Formatted using a default FormatBase. * * When passed a null or blank cell, this method will return an empty * String (""). Formula cells will be evaluated using the given * {@link HSSFFormulaEvaluator} 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 * * * @param cell The cell (can be null) * @param evaluator The HSSFFormulaEvaluator (can be null) * @return a string value of the cell */ public String FormatCellValue(ICell cell, IFormulaEvaluator evaluator) { if (cell == null) { return(""); } CellType cellType = cell.CellType; if (evaluator != null && cellType == CellType.Formula) { try { cellType = evaluator.EvaluateFormulaCell(cell); } catch (Exception e) { throw new Exception("Did you forget to set the current" + " row on the HSSFFormulaEvaluator?", e); } } switch (cellType) { case CellType.Formula: // should only occur if evaluator is null return(cell.CellFormula); case CellType.Numeric: if (DateUtil.IsCellDateFormatted(cell)) { return(GetFormattedDateString(cell)); } return(GetFormattedNumberString(cell)); case CellType.String: return(cell.RichStringCellValue.String); case CellType.Boolean: return(cell.BooleanCellValue.ToString().ToUpper()); case CellType.Blank: return(""); case CellType.Error: return(FormulaError.ForInt(cell.ErrorCellValue).String); } throw new Exception("Unexpected celltype (" + cellType + ")"); }
/** * * Returns the Formatted value of a cell as a <c>String</c> regardless * of the cell type. If the Excel FormatBase pattern cannot be Parsed then the * cell value will be Formatted using a default FormatBase. * * When passed a null or blank cell, this method will return an empty * String (""). Formula cells will be evaluated using the given * {@link HSSFFormulaEvaluator} 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 * * * @param cell The cell (can be null) * @param evaluator The HSSFFormulaEvaluator (can be null) * @return a string value of the cell */ public String FormatCellValue(ICell cell, IFormulaEvaluator evaluator) { if (cell == null) { return(""); } CellType cellType = cell.CellType; if (evaluator != null && cellType == CellType.Formula) { if (evaluator == null) { return(cell.CellFormula); } cellType = evaluator.EvaluateFormulaCell(cell); } switch (cellType) { case CellType.Formula: // should only occur if evaluator is null return(cell.CellFormula); case CellType.Numeric: if (DateUtil.IsCellDateFormatted(cell)) { return(GetFormattedDateString(cell)); } return(GetFormattedNumberString(cell)); case CellType.String: return(cell.RichStringCellValue.String); case CellType.Boolean: return(cell.BooleanCellValue ? "TRUE" : "FALSE"); case CellType.Blank: return(""); case CellType.Error: return(FormulaError.ForInt(cell.ErrorCellValue).String); } throw new Exception("Unexpected celltype (" + cellType + ")"); }
static FormulaError() { _values = new FormulaError[] { FormulaError.NULL, FormulaError.DIV0, FormulaError.VALUE, FormulaError.REF, FormulaError.NAME, FormulaError.NUM, FormulaError.NA, FormulaError.CIRCULAR_REF, FormulaError.FUNCTION_NOT_IMPLEMENTED }; foreach (FormulaError error in _values) { bmap.Add(error.Code, error); imap.Add(error.LongCode, error); smap.Add(error.String, error); } }
/// <summary> /// Set a error value for the cell /// </summary> /// <param name="error">the error value to Set this cell to. /// For formulas we'll Set the precalculated value , for errors we'll set /// its value. For other types we will change the cell to an error cell and Set its value. /// </param> public void SetCellErrorValue(FormulaError error) { _cell.t = (ST_CellType.e); _cell.v = (error.String); }
private ErrorEval(FormulaError error) { _error = error; if (!evals.ContainsKey(error)) evals.Add(error, this); }