123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 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<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("信息表");
- 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 (KeyValuePair<string,string>kv 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+"retaine_" + day;
- FileStream file = new FileStream(@"F:\excel\"+txtName+".xls", FileMode.CreateNew, FileAccess.Write);
- workbook.Write(file);
- file.Dispose();
- }
- }
- public class User
- {
- /// <summary>
- /// 索引
- /// </summary>
- public int Id { get; set; }
- public string Name { get; set; }
- public string pwd { get; set; }
- public string type { get; set; }
- }
- public class Model
- {
- /// <summary>
- /// 索引
- /// </summary>
- public int Id { get; set; }
- public string Name { get; set; }
- public int pwd { get; set; }
- public string type { get; set; }
- }
- }
|