In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Form controls allow users to quickly populate template documents with data and easily reference and interact with cell data. This article introduces how to add form controls to Excel tables, including text boxes, radio buttons, check boxes, combo boxes, spinner buttons, etc., and how to delete specified form controls in Excel through Java code examples.
Program running environment: Java, IDEA, jdk1.8.0, no need to install Microsoft Excel
Tools: Free Spire.XLS for Java (Free Edition)
Java Example 1: Adding a Form Control
import com.spire.xls.*; import com.spire.xls.core.*; public class AddFormControl { public static void main(String[] args) { //Create workbook, get first worksheet Workbook wb = new Workbook(); Worksheet sheet = wb.getWorksheets().get(0); sheet.getCellRange("A2").setText("Name: "); //add text box ITextBoxShape textbox = sheet.getTextBoxes().addTextBox(2, 2, 18, 65); textbox.setText("Li Hong"); textbox.setHAlignment(CommentHAlignType.Center); textbox.setVAlignment(CommentVAlignType.Center); sheet.getCellRange("A4").setText("Gender: "); //Add radio button 1 IRadioButton radiobutton1 = sheet.getRadioButtons().add(4, 2, 18, 65); radiobutton1.setText("male"); radiobutton1.setCheckState(CheckState.Checked); //Add radio button 2 IRadioButton radiobutton2 = sheet.getRadioButtons().add(4, 4, 18, 65); radiobutton2.setText("female"); sheet.getCellRange("A6").setText("Hobby: "); //Add checkbox 1 ICheckBox checkbox1 = sheet.getCheckBoxes().addCheckBox(6, 2, 18, 65); checkbox1.setCheckState(CheckState.Checked); checkbox1.setText("Photo"); //Add checkbox 2 ICheckBox checkbox2 = sheet.getCheckBoxes().addCheckBox(6, 4, 18, 65); checkbox2.setCheckState(CheckState.Checked); checkbox2.setText("Go"); sheet.getCellRange("A8").setText("Occupation: "); sheet.getCellRange("A20").setText("Student"); sheet.getCellRange("A21").setText("Teacher"); sheet.getCellRange("A22").setText("Doctor"); //Add combo box IComboBoxShape combobox = sheet.getComboBoxes().addComboBox(8, 2, 18, 65); combobox.setListFillRange(sheet.getCellRange("A20:A22")); combobox.setSelectedIndex(2); sheet.getCellRange("A10").setText("Executive Level: "); //Add a fine adjustment button 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); //Save document wb.saveToFile("AddControls.xlsx", ExcelVersion.Version2013); wb.dispose(); }}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.