// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; var originalRange = worksheet.Range["B2:D4"]; originalRange.Merge(); originalRange.Value = "元の範囲"; originalRange.Font.Bold = true; originalRange.Font.Color = Color.FromArgb(226, 231, 243); originalRange.Interior.Color = Color.FromArgb(145, 167, 214); originalRange.HorizontalAlignment = HorizontalAlignment.Center; originalRange.VerticalAlignment = VerticalAlignment.Center; // 範囲のオフセットを取得し、値とスタイルを設定 var offsetRange = worksheet.Range["B2:D4"].Offset(4, 4); offsetRange.Merge(); offsetRange.Value = "オフセット範囲"; offsetRange.Font.Bold = true; offsetRange.Font.Color = Color.FromArgb(226, 231, 243); offsetRange.Interior.Color = Color.FromArgb(56, 93, 171); offsetRange.HorizontalAlignment = HorizontalAlignment.Center; offsetRange.VerticalAlignment = VerticalAlignment.Center; // xlsx ファイルに保存 workbook.Save("RangeOffset.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) With worksheet.Range("B2:D4") .Merge() .Value = "元の範囲" .Font.Bold = True .Font.Color = Color.FromArgb(226, 231, 243) .Interior.Color = Color.FromArgb(145, 167, 214) .HorizontalAlignment = HorizontalAlignment.Center .VerticalAlignment = VerticalAlignment.Center End With ' 範囲のオフセットを取得し、値とスタイルを設定 With worksheet.Range("B2:D4").Offset(4, 4) .Merge() .Value = "オフセット範囲" .Font.Bold = True .Font.Color = Color.FromArgb(226, 231, 243) .Interior.Color = Color.FromArgb(56, 93, 171) .HorizontalAlignment = HorizontalAlignment.Center .VerticalAlignment = VerticalAlignment.Center End With ' xlsx ファイルに保存 workbook.Save("RangeOffset.xlsx")