private void LoadExcelDataNew(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e) { try { if (e.Arguments.Length > 0) { var id = e.Arguments[0].ToString(); List <Dictionary <string, object> > result = new List <Dictionary <string, object> >(); var is2007 = false; if (FileHashRel[id].ToLower().IndexOf("xlsx") != -1) { is2007 = true; } var stream = File.OpenRead(FileHashRel[id]); NPOIData svr = new NPOIData(); if (string.IsNullOrEmpty(CurrentRuleList[id].RefStart)) { CurrentRuleList[id].RefStart = "1"; } var list = svr.getSheetInfo(stream, is2007, CurrentRuleList[id].RefStart, ""); e.SetReturnValue(JSON.SerializeObject(list)); } } catch (Exception ex) { ExecScript("alert('" + ex.Message + "')"); } //Task.Factory.StartNew(ProcessExcelData); }
public void ProcessExcelData() { try { List <Dictionary <string, object> > result = new List <Dictionary <string, object> >(); var is2007 = false; if (filepath.ToLower().IndexOf("xlsx") != -1) { is2007 = true; } var stream = File.OpenRead(filepath); NPOIData svr = new NPOIData(); if (string.IsNullOrEmpty(CurrentRule.StartLine)) { CurrentRule.StartLine = "1"; } var list = svr.getSheetInfo(stream, is2007, CurrentRule.StartLine, ""); if (list.Count > 0) { Dictionary <string, object> dictMap = new Dictionary <string, object>(); DataRow row = list[0].dt.Rows[0]; foreach (DataColumn col in list[0].dt.Columns) { var label = row[col.ColumnName].ToString(); var res = CurrentRule.Cols.Where(p => p.FName == label).ToList(); if (res.Count > 0) { dictMap.Add(res[0].FCode, col.ColumnName); continue; } } for (var i = 1; i < list[0].dt.Rows.Count; i++) { Dictionary <string, object> obj = new Dictionary <string, object>(); var dataRow = list[0].dt.Rows[i]; foreach (var item in CurrentRule.Cols) { var key = item.FCode; if (dictMap.ContainsKey(key)) { obj.Add(key, dataRow[dictMap[key].ToString()]); } else { obj.Add(key, item.DeafultValue == null ? "" : item.DeafultValue); } } result.Add(obj); } } result = iservice.ImportTmpTable(result, CurrentRule); ExecScript("ImportController.setData('" + JSON.SerializeObject(result) + "')"); } catch (Exception ex) { ExecScript("ImportController.showError('" + ex.Message + "')"); } }