// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1:G1"].Merge(); worksheet.Range["A1:G1"].Value = "積集合"; worksheet.Range["A1:G1"].HorizontalAlignment = HorizontalAlignment.Center; worksheet.Range["A2:E6"].Interior.Color = Color.FromArgb(145, 167, 214); worksheet.Range["C4:G8"].Interior.Color = Color.FromArgb(145, 167, 214); // 2つの範囲の積集合を取得し、値とスタイルを設定 var intersectRange = worksheet.Range["A2:E6"].Intersect(worksheet.Range["C4:G8"]); intersectRange.Interior.Color = Color.FromArgb(56, 93, 171); intersectRange.Merge(); intersectRange.Value = "積集合の範囲"; intersectRange.Font.Bold = true; intersectRange.Font.Color = Color.FromArgb(226, 231, 243); intersectRange.HorizontalAlignment = HorizontalAlignment.Center; intersectRange.VerticalAlignment = VerticalAlignment.Center; worksheet.Range["A10:G10"].Merge(); worksheet.Range["A10:G10"].Value = "和集合"; worksheet.Range["A10:G10"].HorizontalAlignment = HorizontalAlignment.Center; worksheet.Range["A10:G10"].VerticalAlignment = VerticalAlignment.Center; var firstUnionRange = worksheet.Range["A11:D13"]; firstUnionRange.Merge(); firstUnionRange.Interior.Color = Color.FromArgb(56, 93, 171); firstUnionRange.HorizontalAlignment = HorizontalAlignment.Center; firstUnionRange.VerticalAlignment = VerticalAlignment.Center; var secondUnionRange = worksheet.Range["D14:G16"]; secondUnionRange.Merge(); secondUnionRange.Interior.Color = Color.FromArgb(145, 167, 214); secondUnionRange.HorizontalAlignment = HorizontalAlignment.Center; secondUnionRange.VerticalAlignment = VerticalAlignment.Center; // 2つの範囲の和集合を取得し、値とフォントスタイルを設定 var unionRange = worksheet.Range["A11:D13"].Union(worksheet.Range["D14:G16"]); unionRange.Value = "和集合の範囲"; unionRange.Font.Bold = true; unionRange.Font.Color = Color.FromArgb(226, 231, 243); // xlsx ファイルに保存 workbook.Save("RangeIntersectAndUnion.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim Worksheet As IWorksheet = workbook.Worksheets(0) With Worksheet.Range("A1:G1") .Merge() .Value = "積集合" .HorizontalAlignment = HorizontalAlignment.Center End With Worksheet.Range("A2:E6").Interior.Color = Color.FromArgb(145, 167, 214) Worksheet.Range("C4:G8").Interior.Color = Color.FromArgb(145, 167, 214) ' 2つの範囲の積集合を取得し、値とスタイルを設定 With Worksheet.Range("A2:E6").Intersect(Worksheet.Range("C4:G8")) .Interior.Color = Color.FromArgb(56, 93, 171) .Merge() .Value = "積集合の範囲" .Font.Bold = True .Font.Color = Color.FromArgb(226, 231, 243) .HorizontalAlignment = HorizontalAlignment.Center .VerticalAlignment = VerticalAlignment.Center End With With Worksheet.Range("A10:G10") .Merge() .Value = "和集合" .HorizontalAlignment = HorizontalAlignment.Center .VerticalAlignment = VerticalAlignment.Center End With With Worksheet.Range("A11:D13") .Merge() .Interior.Color = Color.FromArgb(56, 93, 171) .HorizontalAlignment = HorizontalAlignment.Center .VerticalAlignment = VerticalAlignment.Center End With With Worksheet.Range("D14:G16") .Merge() .Interior.Color = Color.FromArgb(145, 167, 214) .HorizontalAlignment = HorizontalAlignment.Center .VerticalAlignment = VerticalAlignment.Center End With ' 2つの範囲の和集合を取得し、値とフォントスタイルを設定 With Worksheet.Range("A11:D13").Union(Worksheet.Range("D14:G16")) .Value = "和集合の範囲" .Font.Bold = True .Font.Color = Color.FromArgb(226, 231, 243) End With ' xlsx ファイルに保存 workbook.Save("RangeIntersectAndUnion.xlsx")