java表单控件_Java 添加、删除Excel表单控件

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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值