|
@@ -20,67 +20,7 @@ namespace DataTransfer.tongji
|
|
|
{
|
|
|
class loseUserDataTransfer
|
|
|
{
|
|
|
- public static void excelText111()
|
|
|
- {
|
|
|
- //导出:将数据库中的数据,存储到一个excel中
|
|
|
-
|
|
|
- //1、查询数据库数据
|
|
|
-
|
|
|
- User user1 = new User() { Id = 1, Name = "小明", pwd = "123123", type = "学生" };
|
|
|
- User user2 = new User() { Id = 2, Name = "小红", pwd = "123123", type = "学生" };
|
|
|
- User user3 = new User() { Id = 3, Name = "小绿", pwd = "123123", type = "学生" };
|
|
|
- User user4 = new User() { Id = 4, Name = "小白", pwd = "123123", type = "老师" };
|
|
|
- User user5 = new User() { Id = 5, Name = "小黑", pwd = "123123", type = "老师" };
|
|
|
- User user6 = new User() { Id = 6, Name = "小蓝", pwd = "123123", type = "老师" };
|
|
|
- List<User> list = new List<User>();
|
|
|
- list.Add(user1);
|
|
|
- list.Add(user2);
|
|
|
- list.Add(user3);
|
|
|
- list.Add(user4);
|
|
|
- list.Add(user5);
|
|
|
- list.Add(user6);
|
|
|
-
|
|
|
- //2、 生成excel
|
|
|
- //2_1、生成workbook
|
|
|
- //2_2、生成sheet
|
|
|
- //2_3、遍历集合,生成行
|
|
|
- //2_4、根据对象生成单元格
|
|
|
- HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
- //创建工作表
|
|
|
- var sheet = workbook.CreateSheet("信息表");
|
|
|
- //创建标题行(重点) 从0行开始写入
|
|
|
- var row = sheet.CreateRow(0);
|
|
|
- //创建单元格
|
|
|
- var cellid = row.CreateCell(0);
|
|
|
- cellid.SetCellValue("编号");
|
|
|
- var cellname = row.CreateCell(1);
|
|
|
- cellname.SetCellValue("用户名");
|
|
|
- var cellpwd = row.CreateCell(2);
|
|
|
- cellpwd.SetCellValue("密码");
|
|
|
- var celltype = row.CreateCell(3);
|
|
|
- celltype.SetCellValue("类型");
|
|
|
-
|
|
|
- //遍历集合,生成行
|
|
|
- int index = 1; //从1行开始写入
|
|
|
- for (int i = 0; i < list.Count; i++)
|
|
|
- {
|
|
|
- int x = index + i;
|
|
|
- var rowi = sheet.CreateRow(x);
|
|
|
- var id = rowi.CreateCell(0);
|
|
|
- id.SetCellValue(list[i].Id);
|
|
|
- var name = rowi.CreateCell(1);
|
|
|
- name.SetCellValue(list[i].Name);
|
|
|
- var pwd = rowi.CreateCell(2);
|
|
|
- pwd.SetCellValue(list[i].pwd);
|
|
|
- var type = rowi.CreateCell(3);
|
|
|
- type.SetCellValue(list[i].type);
|
|
|
- }
|
|
|
-
|
|
|
- FileStream file = new FileStream(@"F:\excel\信息表.xls", FileMode.CreateNew, FileAccess.Write);
|
|
|
- workbook.Write(file);
|
|
|
- file.Dispose();
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
public static void excelText(string memKey,int retain,int zoneid,float day)
|
|
|
{
|
|
|
//获取redis种的数据
|
|
@@ -93,6 +33,37 @@ namespace DataTransfer.tongji
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ Dictionary<string, string> levelDic = new Dictionary<string, string>();
|
|
|
+ Dictionary<string, string> taskDic = new Dictionary<string, string>();
|
|
|
+ Dictionary<string, string> gateDic = new Dictionary<string, string>();
|
|
|
+
|
|
|
+ foreach (var item in ctxList)
|
|
|
+ {
|
|
|
+ string[] sList = item.ToString().Split(':');
|
|
|
+ string type = sList[0];
|
|
|
+ string num = sList[1];
|
|
|
+
|
|
|
+ string[] ctx = type.Split('-');
|
|
|
+ string name = ctx[0];
|
|
|
+ //string id = ctx[1];
|
|
|
+
|
|
|
+ if (name == "level")
|
|
|
+ {
|
|
|
+ levelDic[type] = num;
|
|
|
+ }
|
|
|
+ else if (name == "task")
|
|
|
+ {
|
|
|
+ taskDic[type] = num;
|
|
|
+ }
|
|
|
+ else if (name == "gateId")
|
|
|
+ {
|
|
|
+ gateDic[type] = num;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Dictionary<string,string> dic = levelDic.Union(taskDic).ToDictionary(k=>k.Key,v=>v.Value);
|
|
|
+ Dictionary<string, string> newdic = dic.Union(gateDic).ToDictionary(k => k.Key, v => v.Value);
|
|
|
+
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
//创建工作表
|
|
|
var sheet = workbook.CreateSheet("信息表");
|
|
@@ -106,17 +77,14 @@ namespace DataTransfer.tongji
|
|
|
cellpwd.SetCellValue("指标累计值");
|
|
|
|
|
|
int x = 1;
|
|
|
- foreach (var item in ctxList)
|
|
|
+ foreach (KeyValuePair<string,string>kv in newdic)
|
|
|
{
|
|
|
-
|
|
|
- string[] sList = item.ToString().Split(':');
|
|
|
- string type = sList[0];
|
|
|
- int num = int.Parse(sList[1]);
|
|
|
+ string[] sList = kv.Key.Split('-');
|
|
|
+ string name = sList[0];
|
|
|
+ string id = sList[1];
|
|
|
+
|
|
|
+ int num = int.Parse(kv.Value);
|
|
|
|
|
|
- string[] ctx = type.Split('-');
|
|
|
- string name = ctx[0];
|
|
|
- int id = int.Parse(ctx[1]);
|
|
|
-
|
|
|
var rowi = sheet.CreateRow(x);
|
|
|
var cname = rowi.CreateCell(0);
|
|
|
cname.SetCellValue(name);
|