コード例 #1
0
ファイル: WordDocument.cs プロジェクト: schifflee/Rubin
		/// <summary>
		/// Предоставляет экземпляр документа Microsoft Word, созданного в памяти по заданному шаблону
		/// </summary>
		/// <param name="templateName">Полное имя шаблона в формате dot/dotx</param>
		protected WordDocument(string templateName)
		{
			var fileName = DocumentTemplate.ExtractDoc(templateName);

			//офис требует объектных параметров, так что делаем обертки
			object missingObj = Missing.Value;
			object trueObj = true;
			object falseObj = false;
			object templateNameObj = fileName;		  

			//если вылетим здесь, то нужно закрыть приложение ворда, чтоб не висел лишний процесс
			try
			{							
				_application = new Word.Application();
				_document = _application.Documents.Add(ref templateNameObj, ref missingObj,
					ref missingObj, ref missingObj);
			}
			catch (Exception)
			{
				if (_document != null)
				{							 
					_document.Close(ref falseObj, ref missingObj, ref missingObj);
					_document = null;
				}
				if (_application != null)
				{
					 _application.Quit(ref missingObj, ref missingObj, ref missingObj);
					_application = null;
				}			   
			}
		}
コード例 #2
0
        public override void CreatePackage(string fileName)
        {
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("EntrantContract"));

            // Подготовка стилей
            var underlinedText = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single
            };
            var underlinedBoldText = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single,
                Bold           = true
            };
            var boldText = new CharacterFormat
            {
                Bold = true
            };

            // Готовим текст
            string yearPrice = string.Format("{0} {1}", _contract.YearPrice,
                                             RusCurrency.Str((double)_contract.YearPrice));
            string fullPrice = string.Format("{0} {1}", _contract.FullPrice,
                                             RusCurrency.Str((double)_contract.FullPrice));
            string shhets = _contract.ContragentType.Id == 1 ? "2" : "3";

            // Вставляем текст на закладки
            document.InsertToBookmark("Number", _contract.Number, underlinedBoldText);
            document.InsertToBookmark("Date", ((DateTime)_contract.Date).ToString("«dd» MMMM yyyy г."));
            document.InsertToBookmark("YearPrice", yearPrice, underlinedBoldText);
            document.InsertToBookmark("FullPrice", fullPrice, underlinedBoldText);
            document.InsertToBookmark("YearPrice1", yearPrice, underlinedBoldText);
            document.InsertToBookmark("SheetCount", shhets);
            document.InsertToBookmark("AgentInfo", GetAgentInfo());
            document.InsertToBookmark("EntrantInfo", GetEntrantInfo());
            document.InsertToBookmark("EntrantName", _contract.Entrant.FullName, boldText);
            document.InsertToBookmark("AgentName", _contract.PayerName, boldText);
            document.InsertToBookmark("CompetitiveGroup",
                                      string.Format("{0} {1}, {2}, {3} форма обучения",
                                                    _contract.Entrant.Claim.FirstDirection.Code,
                                                    _contract.Entrant.Claim.FirstDirection.Name,
                                                    _contract.Entrant.Claim.GetCompetitiveGroupByPriority(1).EducationLevel.Name,
                                                    _contract.Entrant.Claim.EducationForm.Name), boldText);
            string educationLevel = _contract.Entrant.Claim.EducationLevel.Id == 1 ? "высшего образования" : "среднего профессионального образования";
            string diplomaType    = _contract.Entrant.Claim.EducationLevel.Id == 1 ? "диплом о высшем образовании" : "диплом о среднем профессиональном образовании";

            document.InsertToBookmark("DiplomaType", diplomaType, underlinedText);
            document.InsertToBookmark("EducationLevel", educationLevel, underlinedText);
            document.InsertToBookmark("TrainingTime", _contract.TrainingPeriod.AsPeriod(), underlinedText);

            document.Save(fileName);
        }
コード例 #3
0
        public override void CreatePackage(string fileName)
        {
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("ContractIndividualPlanAgreement"));

            // Подготовка стилей
            var underlinedText = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single
            };
            var underlinedBoldText = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single,
                Bold           = true
            };
            var boldText = new CharacterFormat
            {
                Bold = true
            };

            // Готовим текст
            string yearPrice = string.Format("{0} {1}", _agreement.YearPrice,
                                             RusCurrency.Str((double)_agreement.YearPrice));
            string fullPrice = string.Format("{0} {1}", _agreement.FullPrice,
                                             RusCurrency.Str((double)_agreement.FullPrice));

            // Вставляем текст на закладки
            document.InsertToBookmark("Number", _agreement.Number, underlinedBoldText);
            document.InsertToBookmark("Date", ((DateTime)_agreement.Date).ToString("«dd» MMMM yyyy г."));
            document.InsertToBookmark("YearPrice", yearPrice, underlinedBoldText);
            document.InsertToBookmark("FullPrice", fullPrice, underlinedBoldText);
            document.InsertToBookmark("YearPrice1", yearPrice, underlinedBoldText);
            document.InsertToBookmark("AgentInfo", GetAgentInfo());
            document.InsertToBookmark("EntrantInfo", GetEntrantInfo());
            document.InsertToBookmark("EntrantName", _agreement.EntrantContract.Entrant.FullName, boldText);
            document.InsertToBookmark("AgentName", _agreement.EntrantContract.PayerName, boldText);
            document.InsertToBookmark("TrainingPeriod", _agreement.TrainingPeriod.AsPeriod(), underlinedText);
            document.InsertToBookmark("FullTrainingPeriod", _agreement.EntrantContract.TrainingPeriod.AsPeriod(), underlinedText);
            document.InsertToBookmark("ContractNumber1", _agreement.EntrantContract.Number, underlinedBoldText);
            document.InsertToBookmark("ContractDate1", ((DateTime)_agreement.EntrantContract.Date).ToString("dd.MM.yyyy г."), underlinedBoldText);
            document.InsertToBookmark("ContractNumber2", _agreement.EntrantContract.Number, underlinedText);
            document.InsertToBookmark("ContractDate2", ((DateTime)_agreement.EntrantContract.Date).ToString("dd.MM.yyyy г."), underlinedText);
            document.InsertToBookmark("ContractNumber3", _agreement.EntrantContract.Number, underlinedText);
            document.InsertToBookmark("ContractDate3", ((DateTime)_agreement.EntrantContract.Date).ToString("dd.MM.yyyy г."), underlinedText);
            document.InsertToBookmark("ContractNumber4", _agreement.EntrantContract.Number, underlinedText);
            document.InsertToBookmark("ContractDate4", ((DateTime)_agreement.EntrantContract.Date).ToString("dd.MM.yyyy г."), underlinedText);

            document.Save(fileName);
        }
コード例 #4
0
        public override void CreatePackage(string fileName)
        {
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("ExaminationStatementMiddleEducation"));

            // Подготовка стилей
            var underlinedText = new CharacterFormat
            {
                FontName       = "Times New Roman",
                Size           = 12,
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single
            };
            var underlinedBoldText = new CharacterFormat
            {
                FontName       = "Times New Roman",
                Size           = 12,
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single,
                Bold           = true
            };

            document.InsertToBookmark("ClaimNumber", _claim.Number, underlinedText);

            document.InsertToBookmark("CurrentUser",
                                      string.Format("{0} {1}.{2}.", Session.CurrentUser.LastName,
                                                    Session.CurrentUser.FirstName[0], Session.CurrentUser.Patronymic[0]));

            document.InsertToBookmark("Date",
                                      DateTime.Now.ToString("«dd» MMMM yyyy г."), underlinedText);

            document.InsertToBookmark("EntrantName",
                                      _claim.Person.FullName);

            string middleMark = string.Format("{0}({1} балла)",
                                              _claim.MiddleMark,
                                              RusCurrency.Str(_claim.MiddleMark, true, "целый", "целых", "целых", "сотый", "сотых", "сотых"));

            document.InsertToBookmark("MiddleMark", middleMark);
            document.InsertToBookmark("ProtocolInfo",
                                      string.Format("{0} №{1}",
                                                    ((DateTime)_claim.SchoolCertificateDocuments.First().EntranceExaminationsCheckProtocol.Date).ToString("dd.MM.yyyy г."),
                                                    _claim.SchoolCertificateDocuments.First().EntranceExaminationsCheckProtocol.Number), underlinedBoldText);

            document.Save(fileName, SaveOptions.DocxDefault);
        }
コード例 #5
0
        public override void CreatePackage(string fileName)
        {
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("EnrollmentDisagreementClaim"));

            // Подготовка стилей
            var underlinedText = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single
            };

            // Вставляем текст на закладки

            string direction = string.Format("{0} {1} ({2}), {3} форма обучения",
                                             _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.Direction.Code,
                                             _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.Direction.Name,
                                             _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.EducationProgramType.Name,
                                             _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.EducationForm.Name);

            string direction1 = string.Format("{4}, {0} {1} ({2}), {3} форма обучения",
                                              _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.Direction.Code,
                                              _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.Direction.Name,
                                              _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.EducationProgramType.Name,
                                              _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.EducationForm.Name,
                                              _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.Faculty.Name);

            document.InsertToBookmark("Date", DateTime.Now.ToString("«dd» MMMM yyyy г."), underlinedText);
            document.InsertToBookmark("Date1", DateTime.Now.ToString("«dd» MMMM yyyy г."),
                                      new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single,
                Size           = 16,
                FontName       = "Times New Roman",
                FontColor      = Color.Black
            });
            document.InsertToBookmark("BirthDate", ((DateTime)_claim.IdentityDocuments.First().BirthDate).ToString("dd.MM.yyyy г."));
            document.InsertToBookmark("Citizenship", _claim.IdentityDocuments.First().Citizenship.Name);
            document.InsertToBookmark("CurrentUser", string.Format("{0} {1}.{2}.",
                                                                   Session.CurrentUser.LastName, Session.CurrentUser.FirstName[0], Session.CurrentUser.Patronymic[0]));
            document.InsertToBookmark("Direction", direction);
            document.InsertToBookmark("DocIssueInfo", string.Format("{0}, {1}",
                                                                    _claim.IdentityDocuments.First().Organization,
                                                                    ((DateTime)_claim.IdentityDocuments.First().Date).ToString("dd.MM.yyyy г.")));
            document.InsertToBookmark("DocNumber",
                                      _claim.IdentityDocuments.First().Number);
            document.InsertToBookmark("DocSeries",
                                      _claim.IdentityDocuments.First().Series);
            document.InsertToBookmark("DocumentName",
                                      _claim.IdentityDocuments.First().IdentityDocumentType.Name);
            document.InsertToBookmark("EntrantName",
                                      _claim.Person.FullName);
            document.InsertToBookmark("EnrollmentOrder",
                                      string.Format("№{0} от {1}",
                                                    _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.EnrollmentOrder.Number,
                                                    ((DateTime)_claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.EnrollmentOrder.Date).ToString("dd.MM.yyyy г.")),
                                      new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single,
                Size           = 16,
                FontName       = "Times New Roman",
                FontColor      = Color.Black
            });
            document.InsertToBookmark("EntrantName1",
                                      _claim.Person.FullName);
            document.InsertToBookmark("EntrantName2",
                                      _claim.Person.FullName);
            document.InsertToBookmark("FinanceSource",
                                      _claim.EnrollmentClaims.Where(ec => ec.EnrollmentExceptionOrder != null).First().EnrollmentProtocol.CompetitiveGroup.FinanceSource.NameInDocument);
            document.InsertToBookmark("FacultyName", direction1);

            // Сохраняем в файл
            document.Save(fileName);
        }
コード例 #6
0
        public override void CreatePackage(string fileName)
        {
            // Загружаем документ
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("ExaminationStatement"));

            // Подготовка стилей
            var paragraphStyle = (ParagraphStyle)Style.CreateStyle(StyleTemplateType.Title, document);

            paragraphStyle.ParagraphFormat = new ParagraphFormat
            {
                Alignment          = HorizontalAlignment.Center,
                SpaceBefore        = 0.0,
                LeftIndentation    = 0.0,
                SpecialIndentation = 0.0
            };
            paragraphStyle.CharacterFormat = new CharacterFormat
            {
                FontName  = "Times New Roman",
                Size      = 12.0,
                FontColor = Color.Black
            };
            document.Styles.Add(paragraphStyle);

            // Вставляем текст на закладки
            document.InsertToBookmark("ClaimNumber", _claim.Number);
            document.InsertToBookmark("EntrantName", _claim.Person.FullName);
            document.InsertToBookmark("ExamMark", _claim.TestScore.ToString());
            document.InsertToBookmark("ExamMarkStr", _claim.TestScore.ScoreString());
            document.InsertToBookmark("IaMark", _claim.IndividualAchievementsScore.ToString());
            document.InsertToBookmark("IaMarkStr", _claim.IndividualAchievementsScore.ScoreString());
            document.InsertToBookmark("TotalMark", _claim.TotalScore.ToString());
            document.InsertToBookmark("TotalMarkStr", _claim.TotalScore.ScoreString());

            // Оформляем табличку
            var table = document.GetChildElements(true, ElementType.Table).Cast <Table>().FirstOrDefault();
            int i     = 1;

            // Получаем вступительные испытания
            // СЭ
            foreach (var exam in _claim.EntranceTestResults)
            {
                var row = new TableRow(document);

                var numberCell = new TableCell(document, new Paragraph(document, i.ToString())
                {
                    ParagraphFormat = new ParagraphFormat
                    {
                        Style = paragraphStyle
                    }
                });
                numberCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                row.Cells.Add(numberCell);

                var subjectCell = new TableCell(document, new Paragraph(document, exam.EntranceTest.ExamSubject.Name + " - СЭ")
                {
                    ParagraphFormat = new ParagraphFormat
                    {
                        Style = paragraphStyle
                    }
                });
                subjectCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                row.Cells.Add(subjectCell);

                var scoreCell = new TableCell(document, new Paragraph(document,
                                                                      string.Format("{0} ({1})", exam.Value, ((int)exam.Value).ScoreString()))
                {
                    ParagraphFormat = new ParagraphFormat
                    {
                        Style = paragraphStyle
                    }
                });
                scoreCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                row.Cells.Add(scoreCell);

                var protocolCell = new TableCell(document, new Paragraph(document,
                                                                         string.Format("{0} от {1}", exam.EntranceTest.EntranceExaminationsCheckProtocol.Number,
                                                                                       ((DateTime)exam.EntranceTest.EntranceExaminationsCheckProtocol.Date).ToString("dd.MM.yyyy")))
                {
                    ParagraphFormat = new ParagraphFormat
                    {
                        Style = paragraphStyle
                    }
                });
                protocolCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                row.Cells.Add(protocolCell);

                table.Rows.Add(row);
                i++;
            }

            // ЕГЭ
            foreach (var egeDoc in _claim.EgeDocuments)
            {
                foreach (var exam in egeDoc.EgeResults)
                {
                    var row = new TableRow(document);

                    var numberCell = new TableCell(document, new Paragraph(document, i.ToString())
                    {
                        ParagraphFormat = new ParagraphFormat
                        {
                            Style = paragraphStyle
                        }
                    });
                    numberCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                    row.Cells.Add(numberCell);

                    var subjectCell = new TableCell(document, new Paragraph(document, exam.ExamSubject.Name + " - ЕГЭ")
                    {
                        ParagraphFormat = new ParagraphFormat
                        {
                            Style = paragraphStyle
                        }
                    });
                    subjectCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                    row.Cells.Add(subjectCell);

                    var scoreCell = new TableCell(document, new Paragraph(document,
                                                                          string.Format("{0} ({1})", exam.Value, ((int)exam.Value).ScoreString()))
                    {
                        ParagraphFormat = new ParagraphFormat
                        {
                            Style = paragraphStyle
                        }
                    });
                    scoreCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                    row.Cells.Add(scoreCell);

                    var protocolCell = new TableCell(document, new Paragraph(document,
                                                                             string.Format("{0} от {1}", exam.EntranceExaminationsCheckProtocol.Number,
                                                                                           ((DateTime)exam.EntranceExaminationsCheckProtocol.Date).ToString("dd.MM.yyyy")))
                    {
                        ParagraphFormat = new ParagraphFormat
                        {
                            Style = paragraphStyle
                        }
                    });
                    protocolCell.CellFormat.VerticalAlignment = VerticalAlignment.Center;
                    row.Cells.Add(protocolCell);

                    table.Rows.Add(row);
                    i++;
                }
            }

            document.Save(fileName, SaveOptions.DocxDefault);
        }
コード例 #7
0
        public override void CreatePackage(string fileName)
        {
            // Загружаем документ
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("EnrollmentOrderStatement"));

            // Подготовка стилей
            var underlinedText = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single
            };

            var ec = _claim.EnrollmentClaims.Where(e => e.EnrollmentExceptionOrder == null).FirstOrDefault();

            if (ec == null)
            {
                throw new Exception("Нет приказа о зачислении из которого этот чувак не был бы исключен.");
            }

            // Вставляем текст на закладки
            document.InsertToBookmark("OrderDate",
                                      ((DateTime)ec.EnrollmentProtocol.EnrollmentOrder.Date).ToString("«dd» MMMM yyyy г."));
            document.InsertToBookmark("OrderNumber",
                                      ec.EnrollmentProtocol.EnrollmentOrder.Number,
                                      underlinedText);
            document.InsertToBookmark("TrainingBeginDate",
                                      ((DateTime)ec.EnrollmentProtocol.TrainingBeginDate).ToString("d MMMM yyyy"));
            document.InsertToBookmark("TrainingEndDate",
                                      ((DateTime)ec.EnrollmentProtocol.TrainingEndDate).ToString("d MMMM yyyy г."));
            document.InsertToBookmark("EducationFormName",
                                      ChangeToAccusative(_claim.EnrollmentClaims.First().EnrollmentProtocol.CompetitiveGroup.EducationForm.Name));
            document.InsertToBookmark("FacultyName",
                                      ec.EnrollmentProtocol.Faculty.Name);
            document.InsertToBookmark("DirectionString",
                                      string.Format("Направление подготовки ({0}): {1} {2}",
                                                    ec.EnrollmentProtocol.CompetitiveGroup.EducationProgramType.Name,
                                                    ec.EnrollmentProtocol.CompetitiveGroup.Direction.Code,
                                                    ec.EnrollmentProtocol.CompetitiveGroup.Direction.Name));
            document.InsertToBookmark("TableStringNumber",
                                      ec.StringNumber.ToString());
            document.InsertToBookmark("StudentName",
                                      _claim.Person.FullName);
            document.InsertToBookmark("EnrollmentReason",
                                      ec.EnrollmentProtocol.CompetitiveGroup.FinanceSource.EnrollmentReason);
            document.InsertToBookmark("ClaimNumber",
                                      _claim.Number);
            string totalScore;

            if (_claim.TotalScore > 0)
            {
                totalScore = _claim.TotalScore.ToString();
            }
            else
            {
                totalScore = _claim.MiddleMark.ToString();
            }
            document.InsertToBookmark("TotalScore",
                                      totalScore);
            document.InsertToBookmark("ProtocolInfo",
                                      string.Format("№ {0} от {1}",
                                                    ec.EnrollmentProtocol.Number,
                                                    ((DateTime)ec.EnrollmentProtocol.Date).ToString("dd.MM.yyyy г.")));
            document.InsertToBookmark("StatementDate",
                                      ((DateTime)ec.EnrollmentProtocol.EnrollmentOrder.Date).ToString("dd.MM.yyyy г."));

            document.InsertToBookmark("TrainingPeriod",
                                      _claim.EnrollmentClaims.First().EnrollmentProtocol.TrainingTime.AsPeriod());

            document.Save(fileName, SaveOptions.DocxDefault);
        }
コード例 #8
0
        public override void CreatePackage(string fileName)
        {
            // Извлекаем шаблон
            var document = DocumentModel.Load(DocumentTemplate.ExtractDoc("EnrollmentOrder"));

            // Подготовка стилей
            var underlinedCharacterFormat = new CharacterFormat
            {
                UnderlineColor = Color.Black,
                UnderlineStyle = UnderlineType.Single,
                Size           = 12.0
            };

            var simpleTextFormat = new CharacterFormat
            {
                Size     = 12.0,
                FontName = "Times New Roman"
            };


            // Вставляем текст на закладки
            document.InsertToBookmark("OrderDate",
                                      ((DateTime)_order.Date).ToString("«dd» MMMM yyyy г."), simpleTextFormat);
            document.InsertToBookmark("OrderNumber", _order.Number, underlinedCharacterFormat);
            //document.InsertToBookmark("TrainingBeginDate",
            //	((DateTime)_order.EnrollmentProtocols.First().TrainingBeginDate).ToString("dd MMMM yyyy"));
            document.InsertToBookmark("TrainingBeginDate",
                                      "01 октября 2017", simpleTextFormat);
            document.InsertToBookmark("EducationForm", "заочную", simpleTextFormat);

            // Получаем строку с протоклами
            string namesProtocol = string.Empty;

            foreach (var p in _order.EnrollmentProtocols.OrderBy(p => p.Number))
            {
                namesProtocol += string.Format(" № {0} от {1},", p.Number,
                                               ((DateTime)p.Date).ToString("dd.MM.yyyy г."));
            }
            namesProtocol = namesProtocol.TrimEnd(',');

            document.InsertToBookmark("EnrollmentProtocols", namesProtocol, simpleTextFormat);

            var reasons = document.Sections[3].Clone(true);

            document.Sections.Remove(document.Sections[3]);


            // Вставляем таблицы по протоколам и заполняем их
            var tableTemplate = document.Sections[2];

            for (int i = 0; i < _order.EnrollmentProtocols.Count - 1; i++)
            {
                document.Sections.Add(tableTemplate.Clone(true));
            }

            int tableIndex = 2;

            foreach (var protocol in _order.EnrollmentProtocols)
            {
                var table = document.Sections[tableIndex].GetChildElements(true, ElementType.Table).Cast <Table>().FirstOrDefault();

                // Факультет
                table.Rows[0].Cells[0].Content.LoadText(protocol.Faculty.Name, simpleTextFormat);

                // Направление подготовки
                string directionString = string.Format("Направление подготовки ({0}, {1}): {2} {3}",
                                                       protocol.CompetitiveGroup.EducationProgramType.Name, protocol.CompetitiveGroup.EducationLevel.Name,
                                                       protocol.CompetitiveGroup.Direction.Code, protocol.CompetitiveGroup.Direction.Name);
                table.Rows[1].Cells[0].Content.LoadText(directionString, simpleTextFormat);

                // Срок освоения
                string trainingTime = string.Format("Срок освоения образовательной программы: {0}", protocol.TrainingTime.AsPeriod());
                table.Rows[2].Cells[0].Content.LoadText(trainingTime, simpleTextFormat);

                // Срок окончания
                string trainingEndDate = string.Format("Срок окончания образовательной программы: {0}",
                                                       ((DateTime)protocol.TrainingEndDate).ToString("dd MMMM yyyy г."));
                table.Rows[3].Cells[0].Content.LoadText(trainingEndDate, simpleTextFormat);

                // Список
                var rowTemplate = table.Rows[5];
                foreach (var claim in protocol.EnrollmentClaims.OrderBy(ec => ec.StringNumber))
                {
                    var tableRow = rowTemplate.Clone(true);

                    // №
                    tableRow.Cells[0].Content.LoadText(claim.StringNumber.ToString(), simpleTextFormat);

                    // ФИО
                    tableRow.Cells[1].Content.LoadText(claim.Claim.Person.FullName, simpleTextFormat);

                    // Основание
                    tableRow.Cells[2].Content.LoadText("Внебюджетный приём", simpleTextFormat);

                    // Рег. номер
                    tableRow.Cells[3].Content.LoadText(claim.Claim.Number, simpleTextFormat);

                    // Сумма баллов
                    tableRow.Cells[4].Content.LoadText(claim.Claim.TotalScore.ToString(), simpleTextFormat);
                    tableRow.Cells[0].CellFormat = new TableCellFormat
                    {
                        VerticalAlignment = VerticalAlignment.Center
                    };
                    table.Rows.Add(tableRow);
                }

                // Итог
                var resultRow = table.Rows[4].Clone(true);
                resultRow.Cells[0].Content.LoadText("Итого:", simpleTextFormat);
                resultRow.Cells[1].Content.LoadText(string.Format("Внебюджетный приём - {0}", protocol.EnrollmentClaims.Count), simpleTextFormat);
                table.Rows.Add(resultRow);

                tableIndex++;
            }

            document.Sections.Add(reasons);
            document.Save(fileName);
        }