在 Spreada .NET 中CellType是非常重要的一个功能,通过CellType可以实现数据的显示和数据编辑操作,今天主要讲解通过 Editor 属性实现用户指定的数据输入方式。
首先,我们添加一个用户输入数据的窗体 PopupEditorControl,该窗体需要实现 FarPoint.Win.Spread.CellType.ISubEditor 接口,代码如下:
public partial class PopupEditorControl : Form, FarPoint.Win.Spread.CellType.ISubEditor
{
public event EventHandler CloseUp;
public event EventHandler ValueChanged;
public PopupEditorControl()
{
InitializeComponent();
}
public Point GetLocation(Rectangle rect)
{
// SubEditor的起始位置
return new Point(0);
}
public Size GetPreferredSize()
{
// SubEditor的大小
return this.Size;
}
public Control GetSubEditorControl()
{
return this;
}
public object GetValue()
{
return "10";
}
public void SetValue(object value)
{
}
private void btnOK_Click(object sender, EventArgs e)
{
// 返回选中的数据
ValueChanged(this, EventArgs.Empty);
CloseUp(this, EventArgs.Empty);
}
private void btnCancel_Click(object sender, EventArgs e)
{
// 取消本次操作
CloseUp(this, EventArgs.Empty);
}
}
接下来,我们添加一个CPopupCellType单元格类型,代码如下:
class CPopupCellType : FarPoint.Win.Spread.CellType.TextCellType
{
public CPopupCellType()
{
this.SubEditor = new PopupEditorControl();
}
}
然后,在主窗体中给Spread设置该单元格类型,代码如下:
private void Form1_Load(object sender, EventArgs e)
{
fpSpread1.ActiveSheet.Cells[7, 1].Value = "通过自定义的CPopupCellType单元格类型,可以给用户提供更多的数据输入方式:";
fpSpread1.ActiveSheet.Cells[7, 1].Font = new System.Drawing.Font("微软雅黑", 20f, FontStyle.Bold);
fpSpread1.ActiveSheet.Rows[7].Height = 50;
// 设置单元个类型
fpSpread1.ActiveSheet.Cells[8, 1, 10, 3].CellType = new CPopupCellType();
}
源码下载:
VS2008 + Spread .NET 6
SpreadJS | 下载试用
纯前端表格控件SpreadJS,兼容 450 种以上的 Excel 公式,具备“高性能、跨平台、与 Excel 高度兼容”的产品特性,备受华为、苏宁易购、天弘基金等行业龙头企业的青睐,并被中国软件行业协会认定为“中国优秀软件产品”。SpreadJS 可为用户提供类 Excel 的功能,满足表格文档协同编辑、 数据填报、 类 Excel 报表设计等业务场景需求,极大的降低企业研发成本和项目交付风险。
如下资源列表,可以为您评估产品提供帮助:
葡萄城热门产品
活字格
打通现有软件,快速定制面向未来的个性化应用

SpreadJS
可嵌入您系统的在线Excel的纯前端表格控件

Wyn商业智能
可与企业自有系统深度集成,增强数据分析的 BI 工具
