Posted 10 September 2023, 11:36 pm EST
Hi Scott,
You can create a custom NumberCellType cell and define its NumberFormat as shown in the following lines of code:
public class NumberCellType2 : NumberCellType
{
private FpSpread _spread;
public NumberCellType2(FpSpread spread, string formatCode)
{
_spread = spread;
NumberFormat = formatCode;
}
public string NumberFormat { get; set; }
public override string Format(object obj)
{
GrapeCity.Spreadsheet.NumberFormat numFmt = new GrapeCity.Spreadsheet.NumberFormat(NumberFormat);
var workbook = _spread.AsWorkbook();
var formatter = numFmt.GetFormatter(workbook, workbook.WorkbookSet.Culture);
var result = formatter.Format(obj);
if (result.Success)
{
return result.Text;
}
return base.Format(obj);
}
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
string text = Format(value);
base.PaintCell(g, r, appearance, text, isSelected, isLocked, zoomFactor);
}
}
You can further use this custom class as shown in the following lines of code:
NumberCellType numberCellType = new NumberCellType2(fpSpread1, "0.00####");
numberCellType.DecimalPlaces = 6;
fpSpread1.ActiveSheet.Cells["A1:A10"].CellType = numberCellType;
Kindly refer to the updated sample for full implementation. DecimalPointNumberCell_Mod.zip
Thanks & Regards,
Aastha