// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); object[,] sourceData = new object[,] { { "受注番号", "商品", "カテゴリ", "金額", "日付", "産地" }, { 1, "にんじん", "野菜", 427000, new DateTime(2018, 7, 6), "アメリカ" }, { 2, "ブロッコリー", "野菜", 823900, new DateTime(2018, 7, 7), "イギリス" }, { 3, "バナナ", "果物", 61700, new DateTime(2018, 7, 8), "アメリカ" }, { 4, "バナナ", "果物", 838400, new DateTime(2018, 7, 10), "カナダ" }, { 5, "アスパラガス", "野菜", 262600, new DateTime(2018, 7, 10), "ドイツ" }, { 6, "オレンジ", "果物", 361000, new DateTime(2018, 7, 11), "アメリカ" }, { 7, "ブロッコリー", "野菜", 906200, new DateTime(2018, 7, 11), "オーストラリア" }, { 8, "バナナ", "果物", 690600, new DateTime(2018, 7, 16), "フィリピン" }, { 9, "りんご", "果物", 241700, new DateTime(2018, 7, 16), "日本" }, { 10, "りんご", "果物", 743100, new DateTime(2018, 7, 16), "カナダ" }, { 11, "バナナ", "果物", 825000, new DateTime(2018, 7, 16), "ドイツ" }, { 12, "ブロッコリー", "野菜", 701200, new DateTime(2018, 7, 18), "アメリカ" }, { 13, "にんじん", "野菜", 190300, new DateTime(2018, 7, 20), "ドイツ" }, { 14, "ブロッコリー", "野菜", 282400, new DateTime(2018, 7, 22), "カナダ" }, { 15, "りんご", "果物", 694600, new DateTime(2018, 7, 24), "日本" }, }; IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A:F"].ColumnWidth = 15; worksheet.Range["A1:F16"].Value = sourceData; ITable table = worksheet.Tables.Add(worksheet.Range["A1:F16"], true); table.Columns[3].DataBodyRange.NumberFormat = "¥#,##0"; // テーブル用のスライサーを作成 ISlicerCache cache = workbook.SlicerCaches.Add(table, "商品", "productCache"); // スライサーを追加 ISlicer slicer1 = cache.Slicers.Add(workbook.Worksheets["Sheet1"], "product1", "商品", 30, 550, 100, 200); // スライサーのレイアウトを設定 slicer1.NumberOfColumns = 2; slicer1.RowHeight = 25; slicer1.DisplayHeader = false; slicer1.Shape.Placement = GrapeCity.Documents.Excel.Drawing.Placement.Move; // xlsx ファイルに保存 workbook.Save("ConfigSlicerLayout.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim sourceData As Object(,) = { {"受注 ID", "商品", "カテゴリ", "金額", "日付", "産地"}, {1, "にんじん", "野菜", 427000, #2018-7-6#, "アメリカ"}, {2, "ブロッコリー", "野菜", 823900, #2018-7-7#, "イギリス"}, {3, "バナナ", "果物", 61700, #2018-7-8#, "アメリカ"}, {4, "バナナ", "果物", 838400, #2018-7-10#, "カナダ"}, {5, "アスパラガス", "野菜", 262600, #2018-7-10#, "ドイツ"}, {6, "オレンジ", "果物", 361000, #2018-7-11#, "アメリカ"}, {7, "ブロッコリー", "野菜", 906200, #2018-7-11#, "オーストラリア"}, {8, "バナナ", "果物", 690600, #2018-7-16#, "フィリピン"}, {9, "りんご", "果物", 241700, #2018-7-16#, "日本"}, {10, "りんご", "果物", 743100, #2018-7-16#, "カナダ"}, {11, "バナナ", "果物", 825000, #2018-7-16#, "ドイツ"}, {12, "ブロッコリー", "野菜", 701200, #2018-7-18#, "アメリカ"}, {13, "にんじん", "野菜", 190300, #2018-7-20#, "ドイツ"}, {14, "ブロッコリー", "野菜", 282400, #2018-7-22#, "カナダ"}, {15, "りんご", "果物", 694600, #2018-7-24#, "日本"} } Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A:F").ColumnWidth = 15 worksheet.Range("A1:F16").Value = sourceData Dim table As ITable = worksheet.Tables.Add(worksheet.Range("A1:F16"), True) table.Columns(3).DataBodyRange.NumberFormat = "\\#,##0" ' テーブル用のスライサーを作成 Dim cache As ISlicerCache = workbook.SlicerCaches.Add(table, "商品", "productCache") ' スライサーを追加 Dim slicer1 As ISlicer = cache.Slicers.Add(workbook.Worksheets("Sheet1"), "product1", "商品", 30, 550, 100, 200) ' スライサーのレイアウトを設定 slicer1.NumberOfColumns = 2 slicer1.RowHeight = 25 slicer1.DisplayHeader = False slicer1.Shape.Placement = Placement.Move ' xlsx ファイルに保存 workbook.Save("ConfigSlicerLayout.xlsx")