2012-05-21 54 views
0

我正在準備一份報告,我需要對系統中的每個用戶進行分類。有大約15K用戶。輸出多個列表的最佳方式是什麼?

因此,我正在通過每個用戶,檢查他們的各種條件,並根據條件爲每個用戶分配一個列表。

大約有8-9個列表,這意味着系統中有大約8-9個類別的用戶。

現在我需要以一些易於理解的格式報告這些用戶。我正在考慮一個CSV文件,其中列將表示這些8-9類別,並且在每個列標題下,我將擁有該列表中的用戶。

我可以將所有這些列表寫入一個CSV文件,然後它們會一個顯示在另一個下面。我不知道如何以表格的形式編寫它們,以便閱讀和理解。

E.g.讓我們考慮我有三類用戶。

category1: abc, def, ghi 
category2: lmn, opq, rst 
category3: uvw, xyz, adf 

所以我的輸出應該象下面這樣:

category1  category2  category3 
abc    lmn    uvw 
def    opq    rst 
uvw    xyz    adf 

我接受其他的建議,以及關於如何我可以輸出一個簡單的結果,以理解的格式。

+0

將用戶在不止一個列表? – yamen

+0

理想情況下,用戶不應出現在多個列表中。但是,儘管重疊的可能性很小。 – aspnetdeveloper

回答

0

對於出口數據的目的,或在數據庫中存儲只能使用一種格式:

user category 
user1 category1 
user1 category2 
user2 category1 
user2 category2 

Excel和其他報告平臺可以將此數據旋轉至所需的格式 - 比如

user category1 category2 category3 
user1 x   x 
user2 x      x 
0

如果您將在Excel中使用這些CSV,我相信您現在的格式是理想的。

對於輸出結果;關於像這樣的內容:

// Get categories with all users in it 
// and get max count in a category across all categories 
List<List<Category>> categories = GetCategoriesWithUsers(); 
int maxUsersInCategory = categories.Max(x => x.Count); 

using (StreamWriter writer = new StreamWriter("output.csv") 
{ 
    // Loop through each user per category 
    for (int userCount = 0; userCount < maxUseresInCategory; userCount++) 
    { 
     string outputLine = string.Empty; 

     // Loop through each category 
     foreach(List<Category> category in categories) 
     { 
      // If category end isn't reached, add user 
      if (category.Length > userCount) 
      { 
       outputLine += category[userCount]; 
      } 

      outputLine += ","; 
     } 

     outputLine = outputLine.Remove(outputLine.Length - 1); 
     writer.WriteLine(outputLine); 
    } 
} 
相關問題