와이소프트 님, 안녕하세요.
그레이프시티입니다.
사용하신 코드와 예시 이미지를 함께 공유해주심에 감사드리며,
문의하신 내용에 대하여 다음과 같이 안내 드립니다.
1. 빨간색 박스 질문
PercentCellType에서 0으로 나누는 Formula 계산 결과가 200%로 표기되는 현상은 잘못된 동작입니다. 해당 현상은 향후 출시될 Spread.NET v17에서 픽스될 예정이며, 해당 버전 출시 시 답글로 다시 안내 드리겠습니다. 사용에 불편을 드려 죄송합니다.
A1, B1 셀에 빈 값이 있을 때 B2 셀을 0 또는 빈 셀로 표기하고 싶으신 경우, 아래 샘플 코드와 같이 사용자 정의 PercentCellType을 구현하여 사용하실 수 있습니다.
PercentCellType2 nctPerCent = new PercentCellType2();
nctPerCent.DecimalSeparator = ".";
nctPerCent.DecimalPlaces = 2;
nctPerCent.FixedPoint = true;
this.fpSpread1.ActiveSheet.Cells[1, 1].Formula = "A1/B1";
this.fpSpread1.ActiveSheet.Cells[1, 1].CellType = nctPerCent;
public class PercentCellType2 : FarPoint.Win.Spread.CellType.PercentCellType
{
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
if (value is GrapeCity.CalcEngine.CalcError error && error == GrapeCity.CalcEngine.CalcError.DivideByZero)
{
value = 0; // 빈 셀로 표현하려면 null을 할당합니다.
}
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
}
}
2. 노란색 박스 질문
Formula의 계산 결과가 0일 때, 빈 값으로 처리하고 싶으신 경우,
- 해당 셀의 셀 타입을 GeneralCellType 혹은 NumberCellType 등으로 지정하신 후,
- SheetView의 DisplayZero 속성 값을 false로 설정해주시기 바랍니다.
DisplayZero 속성은 0 값을 셀에 표시할지 여부를 가져오거나 설정할 때 사용하는 속성입니다.
// GeneralCellType 적용 시
FarPoint.Win.Spread.CellType.GeneralCellType generalCellType = new FarPoint.Win.Spread.CellType.GeneralCellType();
this.fpSpread1.ActiveSheet.Cells[1, 3].CellType = generalCellType;
// NumberCellType 적용 시
FarPoint.Win.Spread.CellType.NumberCellType number = new FarPoint.Win.Spread.CellType.NumberCellType();
number.AllowUserFormulas = true;
this.fpSpread1.ActiveSheet.Cells[1, 3].CellType = number;
// 수식 설정 및 DisplayZero를 false로 설정
this.fpSpread1.ActiveSheet.Cells[1, 3].Formula = "SUM(C1:D1)";
this.fpSpread1.ActiveSheet.DisplayZero = false;
감사합니다.
그레이프시티 드림