private static List <ReviewFields> ParceInputFile(MemoryStream input) { List <ReviewFields> rfs = new List <ReviewFields>(); SpreadsheetDocument ssd = SpreadsheetDocument.Open(input, false); WorkbookPart workbookPart = ssd.WorkbookPart; WorksheetPart worksheetPart = workbookPart.WorksheetParts.FirstOrDefault(); Sheets sheets = workbookPart.Workbook.Sheets; Sheet sheet = sheets.GetFirstChild <Sheet>(); SheetData sheetData = worksheetPart.Worksheet.Descendants <SheetData>().FirstOrDefault(); SharedStringTablePart sharedStringPart = workbookPart.SharedStringTablePart; foreach (var row in sheetData.Elements <Row>()) { if (row.RowIndex == 1) { continue; } ReviewFields rf = new ReviewFields(); rf.Discipline = ExcelUtils.GetCellText(sharedStringPart, row, "A"); if (rf.Discipline == null) { continue; } rf.Theme = ExcelUtils.GetCellText(sharedStringPart, row, "B"); if (rf.Theme == null) { continue; } rf.StudentName = ExcelUtils.GetCellText(sharedStringPart, row, "C"); if (rf.StudentName == null) { continue; } rf.StudentGroup = ExcelUtils.GetCellText(sharedStringPart, row, "D"); if (rf.StudentGroup == null) { continue; } rf.ChiefName = ExcelUtils.GetCellText(sharedStringPart, row, "E"); if (rf.ChiefName == null) { continue; } uint number; if (UInt32.TryParse(ExcelUtils.GetCellText(sharedStringPart, row, "F"), out number)) { rf.Evaluation = number; } else { rf.Evaluation = 0; } rf.EvaluatonsSet = GetRandomEvaluationsSet(rf.Evaluation); rfs.Add(rf); } ssd.Close(); return(rfs); }
private static MemoryStream FieldTemplate(ReviewFields rf) { MemoryStream outStream = new MemoryStream(); { outStream.Position = 0; lock (ApplicationContext.templateFile) { ApplicationContext.templateFile.Position = 0; ApplicationContext.templateFile.CopyTo(outStream); } var valueToFill = new Content( new FieldContent("Discipline", rf.Discipline), new FieldContent("Theme", rf.Theme), new FieldContent("StudentName", rf.StudentName), new FieldContent("StudentGroup", rf.StudentGroup), new FieldContent("ChiefName", rf.ChiefName) ); for (int i = 0; i < rf.EvaluatonsSet.Count; i++) { valueToFill.Fields.Add( new FieldContent("High" + (i + 1), rf.EvaluatonsSet[i].High ? "+" : "-")); valueToFill.Fields.Add( new FieldContent("Medium" + (i + 1), rf.EvaluatonsSet[i].Medium ? "+" : "-")); valueToFill.Fields.Add( new FieldContent("Low" + (i + 1), rf.EvaluatonsSet[i].Low ? "+" : "-")); } using (TemplateProcessor tp = new TemplateProcessor(outStream) .SetRemoveContentControls(true)) { tp.FillContent(valueToFill); tp.SaveChanges(); } return(outStream); } }