// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; // PC のデータを設定 worksheet.Range["A2"].Value = "PC"; worksheet.Range["A4:C4"].Value = new string[] { "デバイス", "数量", "単価" }; worksheet.Range["A5:C10"].Value = new object[,] { { "T540p", 12, 9850 }, { "T570", 5, 7460 }, { "Y460", 6, 5400 }, { "Y460F", 8, 6240 } }; // スタイルの設定 worksheet.Range["A2"].RowHeight = 30; worksheet.Range["A2"].Font.Size = 20; worksheet.Range["A2"].Font.Bold = true; worksheet.Range["A4:C4"].Font.Bold = true; worksheet.Range["A4:C4"].Font.Color = Color.White; worksheet.Range["A4:C4"].Interior.Color = Color.LightBlue; worksheet.Range["A5:C10"].Borders[BordersIndex.InsideHorizontal].Color = Color.Orange; worksheet.Range["A5:C10"].Borders[BordersIndex.InsideHorizontal].LineStyle = BorderLineStyle.DashDot; // スタイルと行の高さだけをコピー worksheet.Range["H1"].Value = "前のセルからスタイルと行の高さをコピー"; worksheet.Range["H1"].Font.Color = Color.Red; worksheet.Range["H1"].Font.Bold = true; var pasteOption = new PasteOption { PasteType = PasteType.Formats }; worksheet.Range["A2:C10"].Copy(worksheet.Range["H2"], pasteOption); // モバイル機器のデータを設定 worksheet.Range["H2"].Value = "Mobile"; worksheet.Range["H4:J4"].Value = new string[] { "デバイス", "数量", "単価" }; worksheet.Range["H5:J10"].Value = new object[,] { { "HW-P30", 20, 4200 }, { "IPhone-X", 5, 9888 }, { "IPhone-6s plus", 15, 6880 } }; // 新しいシートを追加 IWorksheet worksheet2 = workbook.Worksheets.Add(); // 新しいシートにスタイルのみをコピー worksheet.Range["A2:C10"].Copy(worksheet2.Range["A2"], pasteOption); worksheet2.Range["A3"].Value = "sheet1 からスタイルをコピー"; worksheet2.Range["A3"].Font.Color = Color.Red; worksheet2.Range["A3"].Font.Bold = true; // xlsx ファイルに保存 workbook.Save("CopyPasteOptions.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) ' PC のデータを設定 worksheet.Range!A2.Value = "PC" worksheet.Range("A4:C4").Value = {"デバイス", "数量", "単価"} worksheet.Range("A5:C10").Value = New Object(,) { {"T540p", 12, 9850}, {"T570", 5, 7460}, {"Y460", 6, 5400}, {"Y460F", 8, 6240} } ' スタイルの設定 worksheet.Range!A2.RowHeight = 30 worksheet.Range!A2.Font.Size = 20 worksheet.Range!A2.Font.Bold = True worksheet.Range("A4:C4").Font.Bold = True worksheet.Range("A4:C4").Font.Color = Color.White worksheet.Range("A4:C4").Interior.Color = Color.LightBlue worksheet.Range("A5:C10").Borders(BordersIndex.InsideHorizontal).Color = Color.Orange worksheet.Range("A5:C10").Borders(BordersIndex.InsideHorizontal).LineStyle = BorderLineStyle.DashDot ' スタイルと行の高さだけをコピー worksheet.Range!H1.Value = "前のセルからスタイルと行の高さをコピー" worksheet.Range!H1.Font.Color = Color.Red worksheet.Range!H1.Font.Bold = True Dim pasteOption As PasteOption = New PasteOption() pasteOption.PasteType = PasteType.Formats worksheet.Range("A2:C10").Copy(worksheet.Range!H2, pasteOption) ' モバイル機器のデータを設定 worksheet.Range!H2.Value = "Mobile" worksheet.Range("H4:J4").Value = {"デバイス", "数量", "単価"} worksheet.Range("H5:J10").Value = New Object(,) { {"HW-P30", 20, 4200}, {"IPhone-X", 5, 9888}, {"IPhone-6s plus", 15, 6880} } ' 新しいシートを追加 Dim worksheet2 As IWorksheet = workbook.Worksheets.Add() ' 新しいシートにスタイルのみをコピー worksheet.Range("A2:C10").Copy(worksheet2.Range!A2, pasteOption) worksheet2.Range!A3.Value = "sheet1 からスタイルをコピー" worksheet2.Range!A3.Font.Color = Color.Red worksheet2.Range!A3.Font.Bold = True ' xlsx ファイルに保存 workbook.Save("CopyPasteOptions.xlsx")