为多个Excel表单使用相同的模板

我正在处理ASP.NET应用程序,其中有一个以.xls格式导出​​实现的function。 每个实现可以有更多的项目,所以每个项目应该在Excel中有单独的工作表。 我有Excel模板,应该用于制作Excel表格。 问题是:此代码创build一个空模板,然后为不使用模板的项目创build工作表。 有select的时间段的天,列周,行动(在给定的时间内完成的事情),花费的时间和细节+工作描述的列。我正在使用ClosedXML。 我废除了不必要的LINQ和单元合并。

public FileContentResult Export(ExportRealizationViewModel newModel) { try { LINQ for employee whose realization is exported; LINQ for projects in realizations; XLWorkbook theWorkBook = new XLWorkbook(Server.MapPath(@"../Template.xlsx")); foreach (var project in projects) { var wsheet = theWorkBook.Worksheets.Add(project); } using (theWorkBook) { foreach (IXLWorksheet ws in theWorkBook.Worksheets) { LINQ for date period of realizations; LINQ for hours column in excel table; LINQ for actions done during time period; LINQ for action details; LINQ for description of work; int num = date.Count(); double summ = 0; int count; int cell; int col; double total; StringBuilder sb = new StringBuilder(); // Cell merging for weeks column... // Date column ... code for filling date column.. // Week column ... code for filling week column and cell formatting... //Action column ... code for filling action column and cell formatting... // Hours column (weekly and total) ... code for filling hours column and cell formatting... //Remark column(details + description) ... code for filling remark column and cell formatting... } MemoryStream stream = new MemoryStream(); theWorkBook.SaveAs(stream); byte[] fileBytes = stream.ToArray(); return File(fileBytes, "application/vnd.ms-excel", "NewFile.xls"); } } catch (Exception) { TempData["Error"] = "Error"; throw; } }