private String ConvertCellValueToString(CellType cellType) { switch (cellType) { case CellType.Blank: return(""); case CellType.Boolean: return(BooleanCellValue ? "TRUE" : "FALSE"); case CellType.String: return(StringCellValue); case CellType.Numeric: return(NumericCellValue.ToString()); case CellType.Error: byte errVal = ErrorCellValue; return(FormulaError.ForInt(errVal).String); case CellType.Formula: if (_value != null) { FormulaValue fv = (FormulaValue)_value; if (fv.GetFormulaType() != CellType.Formula) { return(ConvertCellValueToString(fv.GetFormulaType())); } } return(""); default: throw new InvalidOperationException("Unexpected cell type (" + cellType + ")"); } }
/// <summary> /// Returns a string representation of the cell /// </summary> /// <returns>Formula cells return the formula string, rather than the formula result. /// Dates are displayed in dd-MMM-yyyy format /// Errors are displayed as #ERR<errIdx> /// </returns> public override String ToString() { switch (CellType) { case CellType.Blank: return(""); case CellType.Boolean: return(BooleanCellValue ? "TRUE" : "FALSE"); case CellType.Error: return(ErrorEval.GetText(ErrorCellValue)); case CellType.Formula: return(CellFormula); case CellType.Numeric: if (DateUtil.IsCellDateFormatted(this)) { FormatBase sdf = new SimpleDateFormat("dd-MMM-yyyy"); return(sdf.Format(DateCellValue, CultureInfo.CurrentCulture)); } return(NumericCellValue.ToString()); case CellType.String: return(RichStringCellValue.ToString()); default: return("Unknown Cell Type: " + CellType); } }