im与LinqToExcel一起从Excel导入数据并在BD中显示。我的擅长是由2列(垂直和水平)组成,在水平方向上我有UserName,在垂直左侧我有JobsNames,信息是每个用户的工作时间。
现在,我想获取第二个用户名的时间。因为当foreach到达终点时,我只会得到第一列的小时数。 我该怎么办?
var ExcelList = from model in excelFile.WorksheetRange<SP_ExtrajobsViewModel>("A3", "C18", sheetName) select model; // Var criada para ir buscar a tabela inteira do excel
var colNames = excelFile.GetColumnNames(sheetName, "B2:C2").ToList(); // vai buscar o nome dos users na horizontal
foreach (var item2 in colNames)
{
foreach (var model in ExcelList) // "skip(1) para ignorar a linha lida do header pois a segunda linha é que faz match com o modelo
{
try
{
if (model.Scope2UserFunctionScope != null)
{
var useriditem = _context.TBL_UserFunctionScope.Where(m => m.Name == model.Scope2UserFunctionScope).FirstOrDefault().FunctionScopeID;
//var UserIDitem2 = 3081;
TBL_ExtraJobs item = new TBL_ExtraJobs();
if (model.Hours == null)
{
item.Hours = 0;
item.Remaining = 0;
}
else
{
item.Hours = (decimal)model.Hours;
item.Remaining = (decimal)model.Hours;
}
item.FunctionScopeID = useriditem;
item.UserID = _context.TBL_User.Where(m=> m.Username.Equals(item2)).Select(o => o.UserID).FirstOrDefault();
item.Day = DateTime.UtcNow;
item.Description = "ola";
item.CreateDate = DateTime.UtcNow;
item.CreateBy = userID;
_context.TBL_ExtraJobs.Add(item);
_context.SaveChanges();
}
else
{
//data.Add("<ul>");
//if (a.Month != null) data.Add("<li> Month is required</li>");
//if (a.UserID != null) data.Add("<li> Address is required</li>");
//if (a.GrossMargin != null) data.Add("<li>ContactNo is required</li>");
//if (a.SalesObjective != 0) data.Add("<li>ContactNo is required</li>");
//if (a.ConversionRate != 0) data.Add("<li>ContactNo is required</li>");
//data.Add("</ul>");
//data.ToArray();
//return Json(data, JsonRequestBehavior.AllowGet);
}
}