可以实现一个自定义的单元格类型:
- public class CRegularExpressionCellType : FarPoint.Win.Spread.CellType.RegularExpressionCellType
- {
- public override bool IsValid(object value)
- {
- bool valid = base.IsValid(value);
- if (!valid)
- {
- MessageBox.Show("数据无效,输重新输入!");
- }
- return valid;
- }
- }
复制代码
- private void Form1_Load(object sender, EventArgs e)
- {
- CRegularExpressionCellType reg = new CRegularExpressionCellType();
- reg.RegularExpression = "^\\d{9}$";
- fpSpread1.Sheets[0].Cells[0, 0].CellType = reg;
- }
复制代码 |