private int SortDataLineByID(DataLineInfo dli1, DataLineInfo dli2) { DataCellInfo dci1 = dli1.GetCellData(0); DataCellInfo dci2 = dli2.GetCellData(0); int id1 = int.Parse(dci1.GetValue <string>()); int id2 = int.Parse(dci2.GetValue <string>()); if (id1 == id2) { return(0); } else if (id1 > id2) { return(1); } else { return(-1); } }
private bool ParseToContent(WorkSheet wSheet) { int rowCount = wSheet.RowCount(); int colCount = wSheet.ColumnCount(); int startRow = MIN_ROW_COUNT; for (int j = startRow; j < rowCount; j++) { DataLineInfo content = new DataLineInfo(fields.Count); for (int i = 0; i < fields.Count; i++) { DataFieldInfo fInfo = fields[i]; string value = wSheet.GetValue(j, fInfo.columnIndex); if (fInfo.type == DataFieldType.Dic) { if (string.IsNullOrEmpty(value)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } else { if (int.TryParse(value, out int count)) { int maxLen = -1; if (i == fields.Count - 1) { maxLen = colCount - fInfo.columnIndex - 1; } else { maxLen = fields[i + 1].columnIndex - fInfo.columnIndex - 1; } if (count * 2 > maxLen) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLarge, "" + j, "" + i)); continue; } else { Dictionary <string, string> result = new Dictionary <string, string>(); for (int m = 1; m <= count; m++) { string k = wSheet.GetValue(j, fInfo.columnIndex + 2 * (m - 1) + 1); string v = wSheet.GetValue(j, fInfo.columnIndex + 2 * m); if (result.ContainsKey(k)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLarge, "" + j, "" + i)); result.Clear(); break; } else { result.Add(k, v); } } content.AddCellData(i, j, fInfo.columnIndex, result); } } else { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } } } else if (fInfo.type == DataFieldType.Array) { if (string.IsNullOrEmpty(value)) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } else { if (int.TryParse(value, out int count)) { int maxLen = -1; if (i == fields.Count - 1) { maxLen = colCount - fInfo.columnIndex - 1; } else { maxLen = fields[i + 1].columnIndex - fInfo.columnIndex - 1; } if (count > maxLen) { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_ArrayLarge, "" + j, "" + i)); continue; } else { List <string> result = new List <string>(); for (int m = 1; m <= count; m++) { result.Add(wSheet.GetValue(j, fInfo.columnIndex + m)); } content.AddCellData(i, j, fInfo.columnIndex, result); } } else { logMsg.Add(new ErrorLogData2(LogConst.E_DataContent_DicLen, "" + j, "" + i)); continue; } } } else { string v = wSheet.GetValue(j, fInfo.columnIndex); content.AddCellData(i, j, fInfo.columnIndex, v); } } contents.Add(content); } contents.Sort(SortDataLineByID); return(true); }