// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); Excel.Workbook.ValueJsonSerializer = new CustomObjectJsonSerializer(); IWorksheet worksheet = workbook.Worksheets[0]; CheckBoxListCellType cellType = new CheckBoxListCellType { Direction = CellTypeDirection.Horizontal, TextAlign = CellTypeTextAlign.Right, IsFlowLayout = false, MaxColumnCount = 2, MaxRowCount = 1, HorizontalSpacing = 20, VerticalSpacing = 5, }; cellType.Items.Add(new SelectFieldItem("プレイヤー1", new People { Name = "Tom", Age = 5 })); cellType.Items.Add(new SelectFieldItem("プレイヤー2", new People { Name = "Jerry", Age = 3 })); cellType.Items.Add(new SelectFieldItem("プレイヤー3", new People { Name = "Mario", Age = 6 })); cellType.Items.Add(new SelectFieldItem("プレイヤー4", new People { Name = "Luigi", Age = 4 })); worksheet.Range["A1"].RowHeight = 40; worksheet.Range["A1"].ColumnWidth = 30; worksheet.Range["A1"].CellType = cellType; worksheet.Range["A1"].Value = new object[,] { {new object[]{ new People { Name = "Tom", Age = 5 }, new People { Name = "Mario", Age = 6 }} } }; //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(); // } //} // PDF ファイルに保存 workbook.Save("AddCheckBoxListCellTypeCustomObject.pdf");
' 新規ワークブックの作成 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("プレイヤー1", New People With { .Name = "Tom", .Age = 5 })) .Add(New SelectFieldItem("プレイヤー2", New People With { .Name = "Jerry", .Age = 3 })) .Add(New SelectFieldItem("プレイヤー3", New People With { .Name = "Mario", .Age = 6 })) .Add(New SelectFieldItem("プレイヤー4", New People With { .Name = "Luigi", .Age = 4 })) End With With worksheet.Range!A1 .RowHeight = 40 .ColumnWidth = 30 .CellType = cellType .Value = { { New Object() { New People With { .Name = "Tom", .Age = 5 }, New People With { .Name = "Mario", .Age = 6 } } } } 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 Function 'End Class ' PDF ファイルに保存 workbook.Save("AddCheckBoxListCellTypeCustomObject.pdf")