スライサーをテーブルにコピーする方法については、次のサンプルコードを参照してください。
C# |
コードのコピー
|
---|---|
//ソースデータを定義します object[,] sourceData = new object[,] { { "Order ID", "Product", "Category", "Amount", "Date", "Country" }, { 1, "Carrots", "Vegetables", 4270, new DateTime(2018, 1, 6), "United States" }, { 2, "Broccoli", "Vegetables", 8239, new DateTime(2018, 1, 7), "United Kingdom" }, { 3, "Banana", "Fruit", 617, new DateTime(2018, 1, 8), "United States" }, { 4, "Banana", "Fruit", 8384, new DateTime(2018, 1, 10), "Canada" }, { 5, "Beans", "Vegetables", 2626, new DateTime(2018, 1, 10), "Germany" }, { 6, "Orange", "Fruit", 3610, new DateTime(2018, 1, 11), "United States" }, { 7, "Broccoli", "Vegetables", 9062, new DateTime(2018, 1, 11), "Australia" }, { 8, "Banana", "Fruit", 6906, new DateTime(2018, 1, 16), "New Zealand" }, { 9, "Apple", "Fruit", 2417, new DateTime(2018, 1, 16), "France" }, { 10, "Apple", "Fruit", 7431, new DateTime(2018, 1, 16), "Canada" }, { 11, "Banana", "Fruit", 8250, new DateTime(2018, 1, 16), "Germany" }, { 12, "Broccoli", "Vegetables", 7012, new DateTime(2018, 1, 18), "United States" }, { 13, "Carrots", "Vegetables", 1903, new DateTime(2018, 1, 20), "Germany" }, { 14, "Broccoli", "Vegetables", 2824, new DateTime(2018, 1, 22), "Canada" }, { 15, "Apple", "Fruit", 6946, new DateTime(2018, 1, 24), "France" }, }; //ブックを初期化し、デフォルトのワークシートを取得します var workbook = new Workbook(); 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.00"; //テーブルに対してスライサーキャッシュを作成します ISlicerCache cache = workbook.SlicerCaches.Add(table, "Category", "categoryCache"); //スライサーを追加し、スライサーの範囲をRange["H3:J16"]に設定します ISlicer slicer = cache.Slicers.Add(workbook.Worksheets["Sheet1"], "cate1", "Category", 30, 550, 100, 200); //Range["H3:J16"]にはスライサーの範囲が含まれる必要があり、新しい図形をRange["K3:M16"]にコピーします worksheet.Range["H3:J16"].Copy(worksheet.Range["K3"]); |
スライサーをテーブルから切り取る方法については、次のサンプルコードを参照してください。
C# |
コードのコピー
|
---|---|
//ソースデータを定義します object[,] sourceData = new object[,] { { "Order ID", "Product", "Category", "Amount", "Date", "Country" }, { 1, "Carrots", "Vegetables", 4270, new DateTime(2018, 1, 6), "United States" }, { 2, "Broccoli", "Vegetables", 8239, new DateTime(2018, 1, 7), "United Kingdom" }, { 3, "Banana", "Fruit", 617, new DateTime(2018, 1, 8), "United States" }, { 4, "Banana", "Fruit", 8384, new DateTime(2018, 1, 10), "Canada" }, { 5, "Beans", "Vegetables", 2626, new DateTime(2018, 1, 10), "Germany" }, { 6, "Orange", "Fruit", 3610, new DateTime(2018, 1, 11), "United States" }, { 7, "Broccoli", "Vegetables", 9062, new DateTime(2018, 1, 11), "Australia" }, { 8, "Banana", "Fruit", 6906, new DateTime(2018, 1, 16), "New Zealand" }, { 9, "Apple", "Fruit", 2417, new DateTime(2018, 1, 16), "France" }, { 10, "Apple", "Fruit", 7431, new DateTime(2018, 1, 16), "Canada" }, { 11, "Banana", "Fruit", 8250, new DateTime(2018, 1, 16), "Germany" }, { 12, "Broccoli", "Vegetables", 7012, new DateTime(2018, 1, 18), "United States" }, { 13, "Carrots", "Vegetables", 1903, new DateTime(2018, 1, 20), "Germany" }, { 14, "Broccoli", "Vegetables", 2824, new DateTime(2018, 1, 22), "Canada" }, { 15, "Apple", "Fruit", 6946, new DateTime(2018, 1, 24), "France" }, }; //ブックを初期化し、デフォルトのワークシートを取得します var workbook = new Workbook(); 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.00"; //テーブルに対してスライサーキャッシュを作成します ISlicerCache cache = workbook.SlicerCaches.Add(table, "Category", "categoryCache"); //スライサーを追加し、スライサーの範囲をRange["H3:J16"]に設定します ISlicer slicer = cache.Slicers.Add(workbook.Worksheets["Sheet1"], "cate1", "Category", 30, 550, 100, 200); //Range["H3:J16"]にはスライサーの範囲が含まれる必要があり、新しい図形をRange["K3:M16"]に切り取ります worksheet.Range["H3:J16"].Cut(worksheet.Range["K3"]); |