// Generate a student grade report as a Word document. public void GenerateStudentReport(LocalStudent studentData, string reportPath) { // Ensure that the WordWrapper is disposed when the method finishes using (var wrapper = new WordWrapper()) { // Create a new Word document in memory wrapper.CreateBlankDocument(); // Add a heading to the document wrapper.AppendHeading(String.Format("Grade Report: {0} {1}", studentData.FirstName, studentData.LastName)); wrapper.InsertCarriageReturn(); wrapper.InsertCarriageReturn(); // Output the details of each grade for the student foreach (var grade in SessionContext.CurrentGrades) { // TODO: Exercise 2: Task 2a: Use the IncludeProcessor to determine which fields in the Grade object are tagged // TODO: Exercise 2: Task 2b: Output each tagged item, using the format specified by the properties of the IncludeInReport attribute for each item wrapper.InsertCarriageReturn(); } // Save the Word document wrapper.SaveAs(reportPath); } }
// Generate a student grade report as a Word document. public void GenerateStudentReport(LocalStudent studentData, string reportPath) { // Ensure that the WordWrapper is disposed when the method finishes using (var wrapper = new WordWrapper()) { // Create a new Word document in memory wrapper.CreateBlankDocument(); // Add a heading to the document wrapper.AppendHeading(String.Format("Grade Report: {0} {1}", studentData.FirstName, studentData.LastName)); wrapper.InsertCarriageReturn(); wrapper.InsertCarriageReturn(); // Output the details of each grade for the student foreach (var grade in SessionContext.CurrentGrades) { // Use the IncludeProcessor to determine which fields in the Grade object are tagged List <FormatField> itemsToReport = IncludeProcessor.GetItemsToInclude(grade); // Output each tagged item, using the format specified by the properties of the IncludeInReport attribute for each item foreach (FormatField item in itemsToReport) { wrapper.AppendText(item.Label == string.Empty ? item.Value : item.Label + ": " + item.Value, item.IsBold, item.IsUnderlined); wrapper.InsertCarriageReturn(); } wrapper.InsertCarriageReturn(); } // Encrypt and save the Word document wrapper.EncryptAndSaveToDisk(reportPath); } }
// TODO: Exercise 1: Task 2a: Generate a student grade report as a Word document. public void GenerateStudentReport(LocalStudent studentData, string reportPath) { WordWrapper wrapper = new WordWrapper(); // Create a new Word document in memory wrapper.CreateBlankDocument(); // Add a heading to the document wrapper.AppendHeading(String.Format("Grade Report: {0} {1}", studentData.FirstName, studentData.LastName)); wrapper.InsertCarriageReturn(); wrapper.InsertCarriageReturn(); // Output the details of each grade for the student foreach (var grade in SessionContext.CurrentGrades) { wrapper.AppendText(grade.SubjectName, true, true); wrapper.InsertCarriageReturn(); wrapper.AppendText("Assessment: " + grade.Assessment, false, false); wrapper.InsertCarriageReturn(); wrapper.AppendText("Date: " + grade.AssessmentDateString, false, false); wrapper.InsertCarriageReturn(); wrapper.AppendText("Comment: " + grade.Comments, false, false); wrapper.InsertCarriageReturn(); wrapper.InsertCarriageReturn(); } // Save the Word document wrapper.SaveAs(reportPath); }