Spire.XLS如何插入各种常用控件到Excel工作表中

作者:控件中国网   出处:控件中国网   2016-08-04 10:15:38   阅读:8

微软提供的MS Excel 软件里包含了一系列Windows Forms控件,用户可以在工作表中添加和使用这些控件,Spire.XLS控件同样为广大开发人员提供了该功能,利用控件提供的API轻松实现在工作表中插入文本框、复选框、复选按钮等常用控件,具体可以参考下面的代码:
Insert_Controls.png
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];
ITextBoxShape textbox = ws.TextBoxes.AddTextBox(2, 2, 15, 100);
textbox.Text = "Hello World";
ICheckBox cb = ws.CheckBoxes.AddCheckBox(4, 2, 15, 100);
cb.CheckState = CheckState.Checked;
cb.Text = "Check Box 1";
cb = ws.CheckBoxes.AddCheckBox(4, 4, 15, 100);
cb.CheckState = CheckState.Checked;
cb.Text = "Check Box 2";
cb = ws.CheckBoxes.AddCheckBox(4, 6, 15, 100);
cb.CheckState = CheckState.Checked;
cb.Text = "Check Box 3";
IRadioButton rb = ws.RadioButtons.Add(6, 2, 15, 100);
rb.Text = "Option 1";
rb = ws.RadioButtons.Add(8, 2, 15, 100);
rb.CheckState = CheckState.Checked;
rb.Text = "Option 2";
rb = ws.RadioButtons.Add(10, 2, 15, 100);
rb.Text = "Option 3";
ws.DefaultRowHeight = 15;
wb.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat