4

Excel データのピボットを解除するために利用できる .net ライブラリはありますか? 現在、スプレッドシートからデータを読み取るために LinqToExcel フレームワークを使用しているため、アンピボットを実行するために使用できる動的な linq クエリがあるかどうかはわかりません。提案をありがとう。ところで、複数の列を処理できるソリューションを探しています。

例 元のテーブル

Product Location  Customer1   Customer2   Customer3
  A        X          10         20         100

宛先テーブル

Product Location Customer    Demand
  A        X      Customer1    10
  A        X      Customer2    20
  A        X      Customer3    100
4

1 に答える 1

5

次のようなことを試してください:

var customer1 =
    from c in excel.Worksheet()
    select new
    {
        Product = c["Product"],
        Location = c["Location"],
        Customer = "Customer1",
        Demand = c["Customer1"],
    };

var customer2 =
    from c in excel.Worksheet()
    select new
    {
        Product = c["Product"],
        Location = c["Location"],
        Customer = "Customer2",
        Demand = c["Customer2"],
    };

var customer3 =
    from c in excel.Worksheet()
    select new
    {
        Product = c["Product"],
        Location = c["Location"],
        Customer = "Customer3",
        Demand = c["Customer3"],
    };

var customers = customer1.Union(customer2).Union(customer3);

あなたのコメントに基づいて、これを試してください:

var columns = 4; /* how many columns to unpivot */
var customers =
    from n in Enumerable.Range(2, columns)
    from c in excel.Worksheet()
    select new
    {
        Product = c["Product"].Value,
        Location = c["Location"].Value,
        Column = n.ToString(),
        Demand = c[n].Value,
    };
于 2012-07-25T02:03:46.647 に答える