您的位置:首页 > 其它

DataExcel 设置单元格 编辑控件 radiocheck,checkbox,textedit,combotext,numberedit

2017-07-19 16:56 676 查看
///清除所有行,列,合并单元格,扩展单元格,
dataexcel1.Clear();
///初始化默认行,列
dataexcel1.Init();
//获取列
IColumn column = dataexcel1.GetColumn(1);
//设置列宽
column.Width = 100;
//获取第五行,第一列的单元格
ICell cell = dataexcel1.GetCell("A5");
cell.Text = "文本框:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取列
column = dataexcel1.GetColumn(2);
//设置列宽
column.Width = 100;
//获取第5行,第一列的单元格
cell = dataexcel1.GetCell("B5");
cell.Value = "我是编辑框";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为文本框
cell.OwnEditControl = new Feng.Excel.Edits.CellTextBoxEdit();
//设置进入编辑的方式
cell.EditMode = Feng.Enums.EditMode.Focused | Feng.Enums.EditMode.KeyDown | Feng.Enums.EditMode.Click;

cell = dataexcel1.GetCell("A6");
cell.Text = "单选框:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取第6行,第一列的单元格
Feng.Excel.Edits.CellRadioCheckBox radioedit = new Feng.Excel.Edits.CellRadioCheckBox();
radioedit.Group = "单选组1";
cell = dataexcel1.GetCell("B6");
cell.Caption = "单选框1";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为单选框
cell.OwnEditControl = radioedit;

cell = dataexcel1.GetCell("C6");
cell.Caption = "单选框2";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为单选框
cell.OwnEditControl = radioedit;

cell = dataexcel1.GetCell("D6");
cell.Caption = "单选框3";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为单选框
cell.OwnEditControl = radioedit;

cell = dataexcel1.GetCell("A7");
cell.Text = "复选框:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取第7行,第一列的单元格
Feng.Excel.Edits.CellCheckBox checkedit = new Feng.Excel.Edits.CellCheckBox();
cell = dataexcel1.GetCell("B7");
cell.Value = true;
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
cell.Caption = "是/否";
//设置编辑控件为复选框
cell.OwnEditControl = checkedit;

cell = dataexcel1.GetCell("A8");
cell.Text = "选择日期:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取第8行,第一列的单元格
Feng.Excel.Edits.CellDateTime datetimeedit = new Feng.Excel.Edits.CellDateTime();
cell.FormatType = Feng.Utils.FormatType.DateTime;
cell.FormatString = "yyyy-MM-dd";
cell = dataexcel1.GetCell("B8");
cell.Value = DateTime.Now;
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为复选框
cell.OwnEditControl = datetimeedit;
//设置进入编辑的方式
cell.EditMode = Feng.Enums.EditMode.Focused | Feng.Enums.EditMode.KeyDown | Feng.Enums.EditMode.Click;

cell = dataexcel1.GetCell("A9");
cell.Text = "数字选择:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取第9行,第一列的单元格
Feng.Excel.Edits.CellNumber numberedit = new Feng.Excel.Edits.CellNumber();
cell = dataexcel1.GetCell("B9");
cell.FormatType = Feng.Utils.FormatType.Numberic;
cell.FormatString = "$##0.00";
cell.Value = 365.25;
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为复选框
cell.OwnEditControl = numberedit;
//设置进入编辑的方式
cell.EditMode = Feng.Enums.EditMode.Focused | Feng.Enums.EditMode.KeyDown | Feng.Enums.EditMode.Click;

cell = dataexcel1.GetCell("A10");
cell.Text = "数字文本框:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取第10行,第一列的单元格
Feng.Excel.Edits.CellNumberBoxEdit numtextedit = new Feng.Excel.Edits.CellNumberBoxEdit();
cell = dataexcel1.GetCell("B10");
cell.FormatType = Feng.Utils.FormatType.Numberic;
cell.FormatString = "$##0.00";
cell.Value = 365.25;
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为复选框
cell.OwnEditControl = numtextedit;
//设置进入编辑的方式
cell.EditMode = Feng.Enums.EditMode.Focused | Feng.Enums.EditMode.KeyDown | Feng.Enums.EditMode.Click;

cell = dataexcel1.GetCell("A11");
cell.Text = "下拉文本框:";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.Red;
//设置编辑控件为LABEL 及为不可编辑
cell.OwnEditControl = new Feng.Excel.Edits.CellLabel();

//获取第11行,第一列的单元格
Feng.Excel.Edits.CellComboBox comboedit = new Feng.Excel.Edits.CellComboBox();
cell = dataexcel1.GetCell("B11");
cell.Value = "选项1";
cell.BackColor = Color.AliceBlue;
cell.ForeColor = Color.RosyBrown;
//设置编辑控件为复选框
cell.OwnEditControl = comboedit;
comboedit.Items.AddRange(new string[] { "选项1", "选项2", "选项3", "选项4", "选项5", "选项6", "选项7" });
//设置进入编辑的方式
cell.EditMode = Feng.Enums.EditMode.Focused | Feng.Enums.EditMode.KeyDown | Feng.Enums.EditMode.Click;


效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: