//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); Excel.Workbook.ValueJsonSerializer = new CustomObjectJsonSerializer(); IWorksheet worksheet = workbook.Worksheets[0]; RadioButtonListCellType cellType = new RadioButtonListCellType { Direction = CellTypeDirection.Horizontal, TextAlign = CellTypeTextAlign.Right, IsFlowLayout = false, MaxColumnCount = 2, MaxRowCount = 1, HorizontalSpacing = 20, VerticalSpacing = 5, }; cellType.Items.Add(new SelectFieldItem("player1", new People {Name = "Tom", Age = 5 })); cellType.Items.Add(new SelectFieldItem("player2", new People { Name = "Jerry", Age = 3 })); cellType.Items.Add(new SelectFieldItem("player3", new People { Name = "Mario", Age = 6 })); cellType.Items.Add(new SelectFieldItem("player4", new People { Name = "Luigi", Age = 4 })); worksheet.Range["A1"].RowHeight = 40; worksheet.Range["A1"].ColumnWidth = 25; worksheet.Range["A1"].CellType = cellType; worksheet.Range["A1"].Value = new People { Name = "Tom", Age = 5 }; //class CustomObjectJsonSerializer : IJsonSerializer //{ // public object Deserialize(string json) // { // return Newtonsoft.Json.JsonConvert.DeserializeObject(json); // } // public string Serialize(object value) // { // return Newtonsoft.Json.JsonConvert.SerializeObject(value); // } //} //class People //{ // private int age; // private string name; // public int Age { get => age; set => age = value; } // public string Name { get => name; set => name = value; } // public override bool Equals(object obj) // { // return obj is People people && // age == people.age && // name == people.name; // } // public override int GetHashCode() // { // return age.GetHashCode() ^ name.GetHashCode(); // } //} // Save to a pdf file workbook.Save("AddRadioButtonCellTypeCustomObject.pdf");
' Create a new Workbook Dim workbook As New Workbook Excel.Workbook.ValueJsonSerializer = New CustomObjectJsonSerializer Dim worksheet As IWorksheet = workbook.Worksheets(0) Dim cellType As New CheckBoxListCellType With { .Direction = CellTypeDirection.Horizontal, .TextAlign = CellTypeTextAlign.Right, .IsFlowLayout = False, .MaxColumnCount = 2, .MaxRowCount = 1, .HorizontalSpacing = 20, .VerticalSpacing = 5 } With cellType.Items .Add(New SelectFieldItem("player1", New People With { .Name = "Tom", .Age = 5 })) .Add(New SelectFieldItem("player2", New People With { .Name = "Jerry", .Age = 3 })) .Add(New SelectFieldItem("player3", New People With { .Name = "Mario", .Age = 6 })) .Add(New SelectFieldItem("player4", New People With { .Name = "Luigi", .Age = 4 })) End With With worksheet.Range!A1 .RowHeight = 40 .ColumnWidth = 25 .CellType = cellType .Value = New People With { .Name = "Tom", .Age = 5 } End With 'Friend Class People ' Public Property Age As Integer ' Public Property Name As String ' Public Overrides Function Equals(obj As Object) As Boolean ' Dim people = TryCast(obj, People) ' If people Is Nothing Then ' Return False ' End If ' Return people.Age = Age AndAlso people.Name = Name ' End Function ' Public Overrides Function GetHashCode() As Integer ' Return Age.GetHashCode Xor Name.GetHashCode ' End Function 'End Class 'Friend Class CustomObjectJsonSerializer ' Implements IJsonSerializer ' Public Function Deserialize(json As String) As Object Implements IJsonSerializer.Deserialize ' Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of People)(json) ' End Function ' Public Function Serialize(value As Object) As String Implements IJsonSerializer.Serialize ' If TypeOf value Is People Then ' Return Newtonsoft.Json.JsonConvert.SerializeObject(value) ' End If ' Return Nothing ' End Funct ' save to a pdf file workbook.Save("AddRadioButtonCellTypeCustomObject.pdf")