using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using NPOI.HSSF.UserModel; using System.IO; using StackExchange.Redis; //using System.Threading; //using System.Data; using CSharpUtil; //using Newtonsoft.Json; //using Newtonsoft.Json.Linq; //using System.Diagnostics; namespace DataTransfer.tongji { class loseUserDataTransfer { public static void excelText(string memKey,int retain,int zoneid,float day) { //获取redis种的数据 var mem = Redis.Ins.GetDatabase(0); HashEntry[] ctxList = mem.HashGetAll(memKey); int length = ctxList.Length; if (length <= 0) { return; } Dictionary levelDic = new Dictionary(); Dictionary taskDic = new Dictionary(); Dictionary gateDic = new Dictionary(); 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 dic = levelDic.Union(taskDic).ToDictionary(k=>k.Key,v=>v.Value); Dictionary newdic = dic.Union(gateDic).ToDictionary(k => k.Key, v => v.Value); HSSFWorkbook workbook = new HSSFWorkbook(); //创建工作表 var sheet = workbook.CreateSheet("信息表"); var row = sheet.CreateRow(0); //创建单元格 var cellid = row.CreateCell(0); cellid.SetCellValue("指标类型"); var cellname = row.CreateCell(1); cellname.SetCellValue("指标id"); var cellpwd = row.CreateCell(2); cellpwd.SetCellValue("指标累计值"); int x = 1; foreach (KeyValuePairkv in newdic) { string[] sList = kv.Key.Split('-'); string name = sList[0]; string id = sList[1]; int num = int.Parse(kv.Value); var rowi = sheet.CreateRow(x); var cname = rowi.CreateCell(0); cname.SetCellValue(name); var cid = rowi.CreateCell(1); cid.SetCellValue(id); var cnum = rowi.CreateCell(2); cnum.SetCellValue(num); x += 1; } string txtName = "流失玩家指标累计信息表_" +"zone"+zoneid+"_"+retain+"lose_" + day; FileStream file = new FileStream(@"F:\excel\"+txtName+".xls", FileMode.CreateNew, FileAccess.Write); workbook.Write(file); file.Dispose(); } } //public class User //{ // /// // /// 索引 // /// // public int Id { get; set; } // public string Name { get; set; } // public string pwd { get; set; } // public string type { get; set; } //} public class Model { /// /// 索引 /// public int Id { get; set; } public string Name { get; set; } public int pwd { get; set; } public string type { get; set; } } }