Regarding DropDown Lists and CheckBoxes

Good Day Nanjing Support,

I am currently developing a java application that has to both write to an excel file
with Aspose and also import data from the excel file.
The excel file has dropdowns populated with values from java application and
also has checkboxes which can be set to yes or no.
I am looking for something like

cell.set('A1', arraylist, dropdownType)
cell.set('A2', checkBox)

Also can I import an entire row say from A3 to R3 in one shot...currently I am importing
cell by cell with a counter.

Any help would be highly welcome.

Regards
Joseph


This message was posted using Email2Forum by Laurence.

Hi Joseph,

Thank you for considering Aspose.

You can use different Aspose APIs to add the Dropdown Lists and Checkboxes in your worksheets. Please see the following code samples for your reference.

Sample Code For Adding Checkbox:

//Instantiate a new Workbook.

Workbook workbook = new Workbook();

//Get the first worksheet in the book.

Worksheet worksheet = workbook.getWorksheets().getSheet(0);

//Add a checkbox to the first worksheet in the workbook.

com.aspose.cells.CheckBox checkBox = worksheet.getShapes().addCheckBox(5,5,100,120,50,50);

//Set its text string.

checkBox.setText("Check it!");

//Put a value into B1 cell.

worksheet.getCells().getCell("B1").setValue("LnkCell");

//Set B1 cell as a linked cell for the checkbox.

checkBox.setLinkedCell("B1");

//Save the excel file.

workbook.save("e:\\Excels\\tstcheckboxes.xls");

Sample Code for adding a dropdown list:

//Create a new Workbook.

Workbook workbook = new Workbook();

//Get the first worksheet.

Worksheet sheet = workbook.getWorksheets().getSheet(0);

//Get the worksheet cells collection.

Cells cells = sheet.getCells();

//Input a value.

cells.getCell("B3").setValue("Employee:");

Style style = cells.getCell("B3").getStyle();

style.getFont().setBold(true);

//Set it bold.

cells.getCell("B3").setStyle(style);

//Input some values that denote the input range for the combo box.

cells.getCell("A2").setValue("Emp001");

cells.getCell("A3").setValue("Emp002");

cells.getCell("A4").setValue("Emp003");

cells.getCell("A5").setValue("Emp004");

cells.getCell("A6").setValue("Emp005");

cells.getCell("A7").setValue("Emp006");

//Add a new combo box.

com.aspose.cells.ComboBox comboBox = sheet.getShapes().addComboBox(3, 1, 0, 0, 100, 20);

//Set the linked cell;

comboBox.setLinkedCell("A1");

//Set the input range.

comboBox.setInputRange("=A2:A7");

//Set no. of list lines displayed in the combo box's list portion.

comboBox.setDropDownLines(5);

//Set the combo box with 3-D shading.

comboBox.setShadow(true);

//AutoFit Columns

sheet.autoFitColumns();

//Saves the file.

workbook.save("E:\\Excels\\tstcombobox.xls");

For your second requirement of copying the complete rows, please see the following code sample,

//Create a new Workbook.

Workbook excelWorkbook1 = new Workbook();

//Open the existing excel file.

excelWorkbook1.open("e:\\excels\\input.xls");

//Get the first worksheet in the workbook.

Worksheet wsTemplate = excelWorkbook1.getWorksheets().getSheet(0);

//Get the height of the second row in the worksheet.

double rowheight = wsTemplate.getCells().getRowHeight(1);

//Copy the second row with data, formattings, images and drawing objects to the 12th row in the worksheet.

wsTemplate.getCells().copyRow(wsTemplate.getCells(),1,11);

//Set the destination row height to view the data.

wsTemplate.getCells().setRowHeight(11,rowheight);

//Save the excel file.

excelWorkbook1.save("e:\\excels\\copyrow.xls");

Please do let us know if you need any further assistance, we will be happy to help you.

Thank You & Best Regards,