我正在准备一份报告,其中我需要对系统中的每个用户进行分类。大约有15K个用户。
因此,我检查了每个用户,检查他们的各种条件,并根据这些条件将每个用户分配到一个列表。
大约有8-9个列表,这意味着系统中大约有8-9个类别的用户。
现在我需要用一种简单易懂的格式来报告这些用户。我正在考虑一个CSV文件,其中的列将代表这8-9个类别,在每个列标题下,我将拥有该列表中的用户。
我可以将所有这些列表写入CSV,但它们会一个接一个地出现。我不知道如何才能将它们写成表格格式,以便易于阅读和理解。
例如,让我们考虑一下我有三类用户。
category1: abc, def, ghi
category2: lmn, opq, rst
category3: uvw, xyz, adf
因此,我的输出应该如下所示:
category1 category2 category3
abc lmn uvw
def opq rst
uvw xyz adf
我也对其他关于如何以易于理解的格式输出结果的建议持开放态度。
发布于 2012-05-21 13:33:04
对于导出数据或存储在数据库中,您只能使用一种格式:
user category
user1 category1
user1 category2
user2 category1
user2 category2
Excel和任何其他报表平台都可以将此数据透视为所需的格式-例如
user category1 category2 category3
user1 x x
user2 x x
发布于 2012-05-21 14:12:23
如果你要在像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);
}
}
https://stackoverflow.com/questions/10679726
复制相似问题