// Create a new workbook Workbook workbook = new Workbook(); Workbook.setValueJsonSerializer(new CustomObjectJsonSerializer()); IWorksheet worksheet = workbook.getWorksheets().get(0); RadioButtonListCellType cellType = new RadioButtonListCellType(); cellType.setDirection(CellTypeDirection.Horizontal); cellType.setTextAlign(CellTypeTextAlign.Right); cellType.setIsFlowLayout(false); cellType.setMaxColumnCount(2); cellType.setMaxRowCount(1); cellType.setHorizontalSpacing(20); cellType.setVerticalSpacing(5); cellType.getItems().add(new SelectFieldItem("player1", new People(5, "Tom"))); cellType.getItems().add(new SelectFieldItem("player2", new People(5, "Jerry"))); cellType.getItems().add(new SelectFieldItem("player3", new People(6, "Mario"))); cellType.getItems().add(new SelectFieldItem("player4", new People(4, "Luigi"))); worksheet.getRange("A1").setRowHeight(40); worksheet.getRange("A1").setColumnWidth(25); worksheet.getRange("A1").setCellType(cellType); worksheet.getRange("A1").setValue(new People(6, "Mario")); //public class CustomObjectJsonSerializer implements IJsonSerializer { // Gson gson = new Gson(); // public final Object deserialize(String json) { // return this.json.fromJson(json, JsonElement.class); // } // // public final String serialize(Object value) { // return this.json.toJson(value); // } //} //public class People { // private int age; // private String name; // // public int getAge() { // return age; // } // // public void setAge(int age) { // this.age = age; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public People(int age, String name){ // this.age = age; // this.name = name; // } // // @Override // public boolean equals(Object obj){ // return obj instanceof com.grapecity.documents.excel.examples.features.spreadjsfeatures.celltype.People && age == ((com.grapecity.documents.excel.examples.features.spreadjsfeatures.celltype.People)obj).getAge() && name.equals(((com.grapecity.documents.excel.examples.features.spreadjsfeatures.celltype.People)obj).getName()); // } // // @Override // public int hashCode() { // int hashCode = 17; // // hashCode = 31 * hashCode + this.age; // hashCode = 31 * hashCode + (this.name == null ? 0 : this.name.hashCode()); // // return hashCode; // } //} // Save to an pdf file workbook.save("AddRadioButtonCellTypeCustomObject.pdf");
// Create a new workbook var workbook = Workbook() Workbook.setValueJsonSerializer(CustomObjectJsonSerializer()) val worksheet = workbook.worksheets[0] val cellType = RadioButtonListCellType() cellType.setDirection(CellTypeDirection.Horizontal) cellType.setTextAlign(CellTypeTextAlign.Right) cellType.setIsFlowLayout(false) cellType.setMaxColumnCount(2) cellType.setMaxRowCount(1) cellType.setHorizontalSpacing(20) cellType.setVerticalSpacing(5) cellType.getItems().add(SelectFieldItem("player1", People(5, "Tom"))) cellType.getItems().add(SelectFieldItem("player2", People(5, "Jerry"))) cellType.getItems().add(SelectFieldItem("player3", People(6, "Mario"))) cellType.getItems().add(SelectFieldItem("player4", People(4, "Luigi"))) worksheet.getRange("A1").rowHeight = 40.0 worksheet.getRange("A1").columnWidth = 25.0 worksheet.getRange("A1").cellType = cellType worksheet.getRange("A1").value = People(6, "Mario") //class People(var age: Int, var name: String?) { // override fun equals(obj: Any?): Boolean { // return obj is People && age == obj.age && name == obj.name // } // // override fun hashCode(): Int { // var hashCode = 17 // hashCode = 31 * hashCode + age // hashCode = 31 * hashCode + if (name == null) 0 else name.hashCode() // return hashCode // } //} //class CustomObjectJsonSerializer : IJsonSerializer { // var gson = Gson() // override fun deserialize(json: String): Any { // return gson.fromJson(json, JsonElement::class.java) // } // // override fun serialize(value: Any): String { // return gson.toJson(value) // } //} // Save to an pdf file workbook.save("AddRadioButtonCellTypeCustomObject.pdf")