/// <summary> /// 构造函数 /// </summary> /// <param name="position"></param> /// <param name="dataFormat"></param> /// <param name="formula"></param> public Range(RangePosition position, string dataFormat, string formula, RANGETYPE type, string font, float fontsize, ReoGridVerAlign valign, ReoGridHorAlign halign) { _position = position; _formula = formula; _numberFormatArgs = getDataFormat(dataFormat); _type = type; Font = font; FontSize = fontsize; HAlign = halign; VAlign = valign; }
/// <summary> /// Compare to another argument instance of NumberFormatArgs. /// </summary> /// <param name="obj">Another instance to be compared.</param> /// <returns>true if two argument object are same.</returns> public override bool Equals(object obj) { if (!(obj is NumberFormatArgs)) { return(false); } NumberFormatArgs o = (NumberFormatArgs)obj; return(this.DecimalPlaces == o.DecimalPlaces && this.NegativeStyle == o.NegativeStyle && this.UseSeparator == o.UseSeparator && this.CustomNegativePrefix == o.CustomNegativePrefix && this.CustomNegativePostfix == o.CustomNegativePostfix ); }
/// <summary> /// Format given cell /// </summary> /// <param name="cell">Instance of cell to be formatted</param> /// <returns></returns> public string FormatCell(Cell cell) { object data = cell.InnerData; // check numeric bool isNumeric = false; double value = 0; if (data is double) { value = (double)data; isNumeric = true; } else if (data is int) { value = (double)(int)data; isNumeric = true; } else if (data is long) { value = (double)(long)data; } else if (data is float) { value = (double)(float)data; isNumeric = true; } else if (data is decimal) { value = (double)(decimal)data; isNumeric = true; } else if (data is string) { string strdata = (data as string).Trim(); isNumeric = double.TryParse(strdata, out value); if (!isNumeric) { isNumeric = double.TryParse(strdata.Replace(",", ""), out value); } if (isNumeric) { cell.InnerData = value; } } else if (data is DateTime) { value = ((DateTime)data - new DateTime(1900, 1, 1)).TotalDays; isNumeric = true; } if (isNumeric) { string prefix = null; string postfix = null; INumberFormatArgs arg = cell.DataFormatArgs as INumberFormatArgs; var numberPart = FormatNumberCellAndGetPattern(cell, ref value, arg); if (arg is NumberFormatArgs) { NumberFormatArgs nargs = (NumberFormatArgs)cell.DataFormatArgs; prefix = nargs.CustomNegativePrefix; postfix = nargs.CustomNegativePostfix; } if (arg != null && (arg.NegativeStyle & NumberNegativeStyle.CustomSymbol) == NumberNegativeStyle.CustomSymbol) { numberPart = (value < 0) ? (prefix + numberPart + postfix) : numberPart; } return(value.ToString(numberPart)); } else { return(null); } }