//合并所有data目录下的excel文件为一个,方便统计 private void FileToOne_Click(object sender, RoutedEventArgs e) { UnEnabledButton(); //保存所有数据 PageFeed pgFeed = new PageFeed(); string AppDomainPath = AppDomain.CurrentDomain.BaseDirectory; string DataPath = AppDomainPath + "data\\"; DirectoryInfo root = new DirectoryInfo(DataPath); //遍历目录下所有文件 foreach (FileInfo f in root.GetFiles()) { if (f.Name.Split('_')[0] == "merge") { f.Delete(); } else { try { IWorkbook workbook = null; //新建IWorkbook对象 FileStream fileStream = new FileStream(f.FullName, FileMode.Open, FileAccess.Read); if (f.FullName.IndexOf(".xlsx") > 0) // 2007版本 { workbook = new XSSFWorkbook(fileStream); //xlsx数据读入workbook } else if (f.FullName.IndexOf(".xls") > 0) // 2003版本 { workbook = new HSSFWorkbook(fileStream); //xls数据读入workbook } ISheet sheet = workbook.GetSheetAt(0); //获取第一个工作表 IRow row; // = sheet.GetRow(0); //新建当前工作表行数据 for (int i = 1; i <= sheet.LastRowNum; i++) //对工作表每一行 { row = sheet.GetRow(i); //row读入第i行数据 if (row != null) { //读取pageID string temp = row.GetCell(2).ToString(); pgFeed.allPages.Add(temp, new OnePage(temp)); pgFeed.pageIDList.Add(temp); for (int j = 0; j < 11; j++) { pgFeed.allPages[temp].SetCell(j, row.GetCell(j).ToString()); } } } fileStream.Close(); workbook.Close(); } catch (Exception x) { MessageBox.Show(x.ToString()); } } } string mergeName = "merge_" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); pgFeed.Save2Excel(mergeName); //如果全部都 if (isCustomFormat.IsChecked == true) { pgFeed.CustomFormat(mergeName); } MessageBox.Show("合并完成"); EnabledButton(); }
//获取所有数据 private void GetAllData(string _UserID, string userType, bool isSevenDay) { JObject Jobject = null; End = false; bool isEnd = false; string lasttime = null; string nickName = ""; PageFeed pgFeed = new PageFeed(); //JArray array = (JArray)_tempJObject["data"]["vHomePageFeed"]; //o9GiTuCSz6w4uJRkPUvZeSNo-2_U //o9GiTuOaGdgD_-ZS4YWn5f-p8ZiE for (int i = 1; !isEnd; i++) { //第一次没有lasttime Jobject = GetQuanData(_UserID, i, userType); //101_c4707a5494b0db899f5c7d073ef6b1c3 if (Jobject.ToString().Length > 150) { if (i == 1) { //为lasttime赋值,以便获得后续数据 lasttime = Jobject["data"]["lLastTime"].ToString(); if (Jobject["data"]["vHomePageFeed"][0] != null) { nickName = (string)Jobject["data"]["vHomePageFeed"][0]["stPostSummary"]["postUser"]["nickname"]; } } else { Jobject = GetQuanData(_UserID, i, userType, lasttime); if (Jobject.ToString().Length > 150) { lasttime = Jobject["data"]["lLastTime"].ToString(); } else { isEnd = true; } } //判断是否为此用户所有数据的最后一次 if (Jobject["data"]["lLastTime"].ToString() == "0") { isEnd = true; } else { //有效数据,进行分析 analysePage(Jobject, pgFeed, isSevenDay); if (End) { isEnd = true; } } } else { isEnd = true; } } pgFeed.Save2Excel(nickName); }