import com.spire.xls.*;
import com.spire.xls.core.*;
import java.awt.*;
public class AddControls {
public static void main(String[] args) {
//创建Workbook实例
Workbook workbook = new Workbook();
//获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
sheet.getCellRange("A2").setText("姓名: ");
//添加文本框
ITextBoxShape textbox = sheet.getTextBoxes().addTextBox(2, 2, 18, 65);
textbox.setText("王春娇");
textbox.getFill().setForeColor(Color.PINK);
textbox.setHAlignment(CommentHAlignType.Center);
textbox.setVAlignment(CommentVAlignType.Center);
sheet.getCellRange("A4").setText("性别: ");
//添加单选按钮1
IRadioButton radiobutton1 = sheet.getRadioButtons().add(4, 2, 18, 65);
radiobutton1.setText("男");
radiobutton1.setCheckState(CheckState.Checked);
//添加单选按钮2
IRadioButton radiobutton2 = sheet.getRadioButtons().add(4, 4, 18, 65);
radiobutton2.setText("女");
sheet.getCellRange("A6").setText("爱好: ");
//添加复选框1
ICheckBox checkbox1 = sheet.getCheckBoxes().addCheckBox(6, 2, 18, 65);
checkbox1.setCheckState(CheckState.Checked);
checkbox1.setText("摄影");
//添加复选框2
ICheckBox checkbox2 = sheet.getCheckBoxes().addCheckBox(6, 4, 18, 65);
checkbox2.setCheckState(CheckState.Checked);
checkbox2.setText("阅读");
sheet.getCellRange("A8").setText("职业: ");
sheet.getCellRange("A20").setText("学生");
sheet.getCellRange("A21").setText("教师");
sheet.getCellRange("A22").setText("医生");
//添加组合框
IComboBoxShape combobox = sheet.getComboBoxes().addComboBox(8, 2, 18, 65);
combobox.setListFillRange(sheet.getCellRange("A20:A22"));
combobox.setSelectedIndex(2);
sheet.getCellRange("A10").setText("行政级别:");
//添加微调按钮
ISpinnerShape spinnerShape = sheet.getSpinnerShapes().addSpinner(10,2,18,30);
spinnerShape.setCurrentValue(1);
spinnerShape.setDisplay3DShading(true);
spinnerShape.setLinkedCell(sheet.getCellRange("B10"));
spinnerShape.setMin(1);
spinnerShape.setMax(5);
//保存文档
workbook.saveToFile("Output/AddControls.xlsx", ExcelVersion.Version2013);
}
}