Excel导出问题

我正在从asp.net填写我的Excel表,但在Excel中我得到错误和不正确的值

错误:

小心,我们在您的工作簿中发现了一个或多个可能会导致您的公式错误地进行计算的循环参考。

码:

public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Precise Technology Consultants"; var DataContext = new EmployeeAtdDataContext(); //var EmployeeAtd = DataContext.GetAttendance_Sp(); IEnumerable<GetAtdRecord_SpResult> EmployeeAtd = DataContext.GetAtdRecord_Sp(null).ToList(); var names = (from n in DataContext.EmployeeAtds select n).Distinct(); ViewData["EmplID"] = new SelectList(names, "EmplID", "EmplName"); return View(EmployeeAtd); } public ActionResult About() { return View(); } public ActionResult ToExcel() { var DataContext = new EmployeeAtdDataContext(); var grid = new GridView(); grid.DataSource = DataContext.GetAtdRecord_Sp(null).ToList(); grid.DataBind(); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment; filename=AttendanceSheet.xls"); Response.ContentType = "application/ms-excel"; Response.Charset = ""; StringWriter sw = new StringWriter(); System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw); grid.RenderControl(htw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); return RedirectToAction("Index"); } 

SQL QUERY:

 WITH Times AS ( SELECT emp.EmplID, emp.EmplName, InTime = MIN(atd.RecTime), OutTime = MAX(atd.RecTime), TimeWorked = DATEDIFF(MINUTE, MIN(atd.RecTime), MAX(atd.RecTime)), OverTime = DATEDIFF(MINUTE, MIN(atd.RecTime), MAX(atd.RecTime)) - 480, [DateVisited] = atd.RecDate FROM AtdRecord atd INNER JOIN HrEmployee emp ON atd.EmplID = emp.EmplID GROUP BY emp.EmplID, emp.EmplName, atd.RecDate HAVING COUNT(atd.RecTime) > 1 ) SELECT t.EmplID, t.EmplName, t.InTime, t.OutTime, t.DateVisited, TimeWorked = CONVERT(CHAR(5), DATEADD(MINUTE, t.TimeWorked, 0), 8), OverTime = CASE WHEN t.OverTime < 0 THEN '-' ELSE '' END + CONVERT(CHAR(5), DATEADD(MINUTE, ABS(t.OverTime), 0), 8) FROM Times t 

使用MVC 3和LINQ到SQL

检查最后一列,加class,ti应该display一个值,例如-07:27,但它不 在这里输入图像说明

Excel中的循环引用总是由公式引起的。 使用Excel提供的工具查找包含循环引用的单元格。 然后钻入问题单元格中的公式引用,并parsing所有引用,直到find循环引用的原因。