/** * Adds a new FormatBase to the available formats. * * The value that will be passed to the FormatBase's FormatBase method (specified * by <c>java.text.FormatBase#FormatBase</c>) will be a double value from a * numeric cell. Therefore the code in the FormatBase method should expect a * <c>Number</c> value. * * @param excelformatStr The data FormatBase string * @param FormatBase A FormatBase instance */ public void AddFormat(String excelformatStr, FormatBase format) { formats[excelformatStr]= format; }
/** * * Returns the Formatted value of a cell as a <tt>String</tt> 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 (""). Formulas in formula type cells will not be evaluated. * * * @param cell The cell * @return the Formatted cell value as a String */ //public String FormatCellValue(HSSFCell cell) //{ // return FormatCellValue(cell, null); //} ///** // * // * Returns the Formatted value of a cell as a <tt>String</tt> 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(HSSFCell cell, HSSFFormulaEvaluator evaluator) //{ // if (cell == null) // { // return ""; // } // HSSFCellType cellType = cell.CellType; // if (evaluator != null && cellType == HSSFCellType.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 HSSFCellType.FORMULA: // // should only occur if evaluator is null // return cell.CellFormula; // case HSSFCellType.NUMERIC: // if (HSSFDateUtil.IsCellDateFormatted(cell)) // { // return GetFormattedDateString(cell); // } // return GetFormattedNumberString(cell); // case HSSFCellType.STRING: // return cell.RichStringCellValue.String; // case HSSFCellType.BOOLEAN: // return cell.BooleanCellValue.ToString().ToUpper(); // case HSSFCellType.BLANK: // return ""; // } // throw new Exception("Unexpected celltype (" + cellType + ")"); //} /** * * Sets a default number FormatBase to be used when the Excel FormatBase cannot be * Parsed successfully. <b>Note:</b> This is a fall back for when an error * occurs while parsing an Excel number FormatBase pattern. This will not * affect cells with the <em>General</em> FormatBase. * * * The value that will be passed to the FormatBase's FormatBase method (specified * by <c>java.text.FormatBase#FormatBase</c>) will be a double value from a * numeric cell. Therefore the code in the FormatBase method should expect a * <c>Number</c> value. * * * @param FormatBase A FormatBase instance to be used as a default * @see java.text.FormatBase#FormatBase */ public void SetDefaultNumberFormat(FormatBase format) { IEnumerator itr = formats.Keys.GetEnumerator(); while (itr.MoveNext()) { string key = (string)itr.Current; if (formats[key] == generalDecimalNumFormat || formats[key] == generalWholeNumFormat) { formats[key] = format; } } defaultNumFormat = format; }