// 新規ワークブックの作成 var workbook = new GrapeCity.Documents.Excel.Workbook(); object[,] sourceData = new object[,] { { "受注番号", "商品", "カテゴリ", "金額", "日付", "産地" }, { 1, "にんじん", "野菜", 427000, new DateTime(2018, 1, 6), "アメリカ" }, { 2, "ブロッコリー", "野菜", 823900, new DateTime(2018, 1, 7), "イギリス" }, { 3, "バナナ", "果物", 61700, new DateTime(2018, 6, 8), "アメリカ" }, { 4, "バナナ", "果物", 838400, new DateTime(2019, 1, 10), "カナダ" }, { 5, "アスパラガス", "野菜", 262600, new DateTime(2019, 2, 10), "ドイツ" }, { 6, "オレンジ", "果物", 361000, new DateTime(2019, 1, 11), "アメリカ" }, { 7, "ブロッコリー", "野菜", 906200, new DateTime(2018, 1, 11), "オーストラリア" }, { 8, "バナナ", "果物", 690600, new DateTime(2019, 5, 16), "フィリピン" }, { 9, "りんご", "果物", 241700, new DateTime(2019, 1, 16), "日本" }, { 10, "りんご", "果物", 743100, new DateTime(2019, 1, 16), "カナダ" }, { 11, "バナナ", "果物", 825000, new DateTime(2020, 1, 16), "ドイツ" }, { 12, "ブロッコリー", "野菜", 701200, new DateTime(2019, 3, 18), "アメリカ" }, { 13, "にんじん", "野菜", 190300, new DateTime(2020, 1, 20), "ドイツ" }, { 14, "ブロッコリー", "野菜", 282400, new DateTime(2019, 4, 22), "カナダ" }, { 15, "りんご", "果物", 694600, new DateTime(2020, 1, 24), "日本" }, }; IWorksheet worksheet = workbook.Worksheets[0]; // ピボットテーブルにて日付/時刻列の自動グループ化を無効にします。 workbook.Options.Data.AutomaticGroupDateTimeInPivotTable = false; worksheet.Range["Q1:V16"].Value = sourceData; IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["Q1:V16"]); IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["A1"], "pivottable1"); worksheet.Range["A:A"].ColumnWidth = 15; worksheet.Range["B:P"].ColumnWidth = 10; worksheet.Range["Q:V"].AutoFit(); pivotTable.PivotFields["カテゴリ"].Orientation = PivotFieldOrientation.RowField; pivotTable.PivotFields["商品"].Orientation = PivotFieldOrientation.RowField; pivotTable.PivotFields["日付"].Orientation = PivotFieldOrientation.ColumnField; pivotTable.PivotFields["金額"].Orientation = PivotFieldOrientation.DataField; // xlsx ファイルに保存 workbook.Save("ConfigAutomaticGroupDateTimeInPivotTable.xlsx");
' 新規ワークブックの作成 Dim workbook As New Workbook Dim sourceData(,) As Object = { {"受注番号", "商品", "カテゴリ", "金額", "日付", "産地"}, {1, "にんじん", "野菜", 427000, #2018-1-6#, "アメリカ"}, {2, "ブロッコリー", "野菜", 823900, #2018-1-7#, "イギリス"}, {3, "バナナ", "果物", 61700, #2018-6-8#, "アメリカ"}, {4, "バナナ", "果物", 838400, #2019-1-10#, "カナダ"}, {5, "アスパラガス", "野菜", 262600, #2019-2-10#, "ドイツ"}, {6, "オレンジ", "果物", 361000, #2019-1-11#, "アメリカ"}, {7, "ブロッコリー", "野菜", 906200, #2018-1-11#, "オーストラリア"}, {8, "バナナ", "果物", 690600, #2019-5-16#, "フィリピン"}, {9, "りんご", "果物", 241700, #2019-1-16#, "日本"}, {10, "りんご", "果物", 743100, #2019-1-16#, "カナダ"}, {11, "バナナ", "果物", 825000, #2020-1-16#, "ドイツ"}, {12, "ブロッコリー", "野菜", 701200, #2019-3-18#, "アメリカ"}, {13, "にんじん", "野菜", 190300, #2020-1-20#, "ドイツ"}, {14, "ブロッコリー", "野菜", 282400, #2019-4-22#, "カナダ"}, {15, "りんご", "果物", 694600, #2020-1-24#, "日本"} } Dim worksheet As IWorksheet = workbook.Worksheets(0) ' ピボットテーブルにて日付/時刻列の自動グループ化を無効にします。 workbook.Options.Data.AutomaticGroupDateTimeInPivotTable = False worksheet.Range("Q1:V16").Value = sourceData Dim pivotcache = workbook.PivotCaches.Create(worksheet.Range("Q1:V16")) Dim pivottable = worksheet.PivotTables.Add(pivotcache, worksheet.Range!A1, "pivottable1") worksheet.Range("A:A").ColumnWidth = 15 worksheet.Range("B:P").ColumnWidth = 10 worksheet.Range("Q:V").AutoFit() pivottable.PivotFields!カテゴリ.Orientation = PivotFieldOrientation.RowField pivottable.PivotFields!商品.Orientation = PivotFieldOrientation.RowField pivottable.PivotFields!日付.Orientation = PivotFieldOrientation.ColumnField pivottable.PivotFields!金額.Orientation = PivotFieldOrientation.DataField ' xlsx ファイルに保存 workbook.Save("ConfigAutomaticGroupDateTimeInPivotTable.xlsx")