// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Value = "aaa"; worksheet.Range["A2"].Value = "bbb"; worksheet.Range["A3"].Value = "ccc"; worksheet.Range["C2:E4"].Value = new object[,] { {"aaa", "bbb", "ccc"}, {"aaa1", "bbb1", "ccc1"}, {"aaa2", "bbb2", "ccc2"} }; // リスト入力規則の作成 worksheet.Range["C2:E4"].Validation.Add(ValidationType.List, ValidationAlertStyle.Stop, ValidationOperator.Between, "=$a$1:$a$3"); IValidation validation = worksheet.Range["C2:E4"].Validation; validation.InCellDropdown = true; // 範囲["C2:E4"]に入力規則が設定されているかの判断 for (int i = 1; i <= 3; i++) { for (int j = 2; j <= 4; j++) { if (worksheet.Range[i, j].HasValidation) { // 入力規則が設定されている場合に内部の色を変更 worksheet.Range[i, j].Interior.Color = Color.LightBlue; } } } // xlsx ファイルに保存 workbook.Save("CreateListValidation.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range!A1.Value = "aaa" worksheet.Range!A2.Value = "bbb" worksheet.Range!A3.Value = "ccc" worksheet.Range("C2:E4").Value = New Object(,) { {"aaa", "bbb", "ccc"}, {"aaa1", "bbb1", "ccc1"}, {"aaa2", "bbb2", "ccc2"} } ' リスト入力規則の作成 worksheet.Range("C2:E4").Validation.Add(ValidationType.List, ValidationAlertStyle.Stop, ValidationOperator.Between, "=$a$1:$a$3") Dim validation As IValidation = worksheet.Range("C2:E4").Validation validation.InCellDropdown = True ' 範囲["C2:E4"]に入力規則が設定されているかの判断 For i As Integer = 1 To 3 For j As Integer = 2 To 4 If worksheet.Range(i, j).HasValidation Then ' 入力規則が設定されている場合に内部の色を変更 worksheet.Range(i, j).Interior.Color = Color.LightBlue End If Next j Next i ' xlsx ファイルに保存 workbook.Save("CreateListValidation.xlsx")