public void OpenTask(Exam exam, Ticket ticket, bool markAnswers) { CloseWord(); OneAnswerQuestion[] questions = ticket.GetQuestions().Cast <OneAnswerQuestion>().ToArray(); using (DocX docXdocument = DocX.Create(path.ToString())) { int i, j; docXdocument.AddFooters(); docXdocument.SetDefaultFont(new Xceed.Document.NET.Font("Times New Roman")); Xceed.Document.NET.Paragraph headerParagraph = docXdocument.InsertParagraph(); Xceed.Document.NET.Paragraph paragraph = docXdocument.InsertParagraph(); headerParagraph.Append($"Перегляд завдання") .Bold() .FontSize(28); paragraph.Append($"Завдання білету \"{ticket.TicketName}\":") .FontSize(24); Xceed.Document.NET.Table table = docXdocument.AddTable(questions.Length, 2); table.SetWidthsPercentage(new[] { 50f, 50 }, docXdocument.PageWidth - docXdocument.PageWidth / 5); table.SetBorder(TableBorderType.Bottom, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.Top, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.Left, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.Right, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.InsideV, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); for (i = 0; i < questions.Length; i++) { table.Rows[i].Cells[0] .InsertParagraph() .Append($"{questions[i].QuestionNumber + exam.FirstQuestionNumber}) {questions[i].QuestionContent.Text}") .FontSize(12); Xceed.Document.NET.Paragraph tableParagraph = table.Rows[i].Cells[1].InsertParagraph(); for (j = 0; j < questions[i].QuestionContent.Answers.Count; j++) { Xceed.Document.NET.Paragraph tempParagraph = tableParagraph.Append($"{(j < questions[i].QuestionContent.Letters.Length ? questions[i].QuestionContent.Letters[j].ToString() : "*")}{questions[i].QuestionContent.Devider} { questions[i].QuestionContent.Answers[j]};{Environment.NewLine}"); if (markAnswers && questions[i].Answer.Content == questions[i].QuestionContent.Answers[j]) { tempParagraph.Bold() .FontSize(12); } } } docXdocument.InsertTable(table); docXdocument.Footers.Odd.InsertParagraph() .Append("Створено за допомогою SimplEx Program") .FontSize(10) .UnderlineStyle(UnderlineStyle.singleLine) .Alignment = Alignment.right; docXdocument.Save(); } OpenWord(); }
static void Main(string[] args) { //string path = "test-doc.rtf"; //string readText = File.ReadAllText(path); //var docin = DocX.Load(RtfDocx(readText)); //var tins = docin.Tables[0]; string fileName = @"exempleWord.docx"; doc = DocX.Create(fileName); doc.PageLayout.Orientation = Orientation.Landscape; //Formatting Text Paragraph Formatting textParagraphFormat = new Formatting { //font family FontFamily = new Font("Times New Roman"), //font size Size = 10D, //Spaces between characters //Spacing = 1 }; //Create Table with 2 rows and 3 columns. var header = new string[] { "Было", "Статус", "Стало" }; Table t = doc.AddTable(2, header.Length); t.Alignment = Alignment.center; t.SetWidthsPercentage(new float[] { 45F, 10F, 45F }, doc.PageWidth - 40); // t.Design = TableDesign.TableGrid;SetColumnWidth(t, new int[] { 45, 10, 45 }, doc.PageWidth); //t.AutoFit = AutoFit.Fixed; // t.SetWidthsPercentage(new float[] { 45F,10F, 45F },doc.PageWidth); SetColumnWidth(t, new int[] { 45, 10, 45 }, doc.PageWidth - 40); FillRow(t.Rows[0], header, System.Drawing.Color.LightGray, true); Globals.Load_CradleAPI(); Globals.GetArgs(); //&TBL2&ПД&BL0&БЛ1&&Рзд ПД-37&ТЛ-1 var bl1 = Globals.Args[3]; var bl2 = Globals.Args[4]; var phase = Globals.Args[2]; var proj = new Project(); var ldap = new LDAPInformation(); if (!proj.Connect(Globals.CRADLE_CDS_HOST, Globals.CRADLE_PROJECT_CODE, Globals.CRADLE_USERNAME, Globals.CRADLE_PASSWORD, true, Cradle.Server.Connection.API_LICENCE, ldap, false)) { return; } ; var project = proj; proj.SetBaselineMode(CAPI_BASELINE_MODE.SPECIFIED, bl2); Console.WriteLine("Начало обработки проекта " + proj.Title); int row = 1; Item root = new Item(CAPI_INFO.NOTE, "Раздел ТЗ " + phase); root.Identity = Globals.Args[6]; root.Baseline = bl2; root.Version = "01"; root.Draft = " "; if (root.Open(false)) { root.Close(); OutItems(t, root, ref row); } //SetColumnWidth(t,new int[] { 45, 10, 45 }, doc.PageWidth); doc.InsertTable(t); //SetColumnWidth(t, new int[] { 45, 10, 45 }, doc.PageWidth); //doc.InsertDocument(docin); doc.Save(); Process.Start("WINWORD.EXE", fileName); }
public void OpenBlank(Exam exam, Ticket ticket, bool markAnswers) { CloseWord(); using (DocX docXdocument = DocX.Create(path.ToString())) { int i, j; docXdocument.AddFooters(); docXdocument.SetDefaultFont(new Xceed.Document.NET.Font("Times New Roman"), 14); Xceed.Document.NET.Paragraph headerParagraph = docXdocument.InsertParagraph(); Xceed.Document.NET.Paragraph paragraph = docXdocument.InsertParagraph(); headerParagraph.Append($"Виконання завдань") .Bold() .FontSize(16); paragraph = docXdocument.InsertParagraph(); paragraph.Append($"Здобувач освіти") .Bold() .Append("\t\t\t\t\t\t\t") .UnderlineStyle(UnderlineStyle.singleLine) .Append("білет №") .Bold() .Append("\t\t") .UnderlineStyle(UnderlineStyle.singleLine); paragraph = docXdocument.InsertParagraph(); paragraph.Append($"{Environment.NewLine}I частина") .Bold() .Alignment = Alignment.center; paragraph = docXdocument.InsertParagraph(); paragraph.Append($"\tОзнайомтесь з тестовим завданням. Дайте відповіді на тестові завдання в таблиці" + $"(поряд із номером запитання зазначте номер правильної відповіді){Environment.NewLine}") .Alignment = Alignment.left; List <OneAnswerQuestion[]> questionLists = new List <OneAnswerQuestion[]>(); for (i = 0; i < exam.Themes.Count; i++) { OneAnswerQuestion[] questions = exam.Themes[i].GetQuestions(ticket).Cast <OneAnswerQuestion>().ToArray(); Array.Sort(questions, (Question a, Question b) => { if (a.QuestionNumber > b.QuestionNumber) { return(1); } else if (a.QuestionNumber < b.QuestionNumber) { return(-1); } return(0); }); questionLists.Add(questions); } int max = questionLists.Max(a => a.Length); Xceed.Document.NET.Table table = docXdocument.AddTable(max + 1, questionLists.Count * 2); table.SetBorder(TableBorderType.Bottom, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.Top, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.Left, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); table.SetBorder(TableBorderType.Right, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black)); List <float> percentages = new List <float>(); float pa = 30 / (table.ColumnCount / 2); float pb = 70 / (table.ColumnCount / 2); for (i = 0; i < table.ColumnCount / 2; i += 2) { table.Rows[0].MergeCells(i, i + 1); percentages.Add(pa); percentages.Add(pb); i--; } table.SetWidthsPercentage(percentages.ToArray(), docXdocument.PageWidth - docXdocument.PageWidth / 5); for (i = 0; i < exam.Themes.Count; i++) { table.Rows[0].Cells[i].InsertParagraph() .Append(exam.Themes[i].ThemeName) .Alignment = Alignment.center; } for (i = 0; i < table.ColumnCount / 2; i++) { for (j = 0; j < questionLists[i].Length; j++) { table.Rows[1 + j].Cells[i * 2].InsertParagraph() .Append($"{questionLists[i][j].QuestionNumber + exam.FirstQuestionNumber}"); if (markAnswers) { int index = questionLists[i][j].QuestionContent.Answers.IndexOf(questionLists[i][j].Answer.Content); table.Rows[1 + j].Cells[i * 2 + 1].InsertParagraph() .Append(index >= 0 && index < questionLists[i][j].QuestionContent.Letters.Length ? questionLists[i][j].QuestionContent.Letters[index].ToString() : "*"); } } } docXdocument.InsertTable(table); paragraph = docXdocument.InsertParagraph(); paragraph.Append($"{Environment.NewLine}{Environment.NewLine}Балл: ") .Bold() .Alignment = Alignment.right; if (!markAnswers) { paragraph.Append("\t\t") .UnderlineStyle(UnderlineStyle.singleLine) .Alignment = Alignment.right; } else { paragraph.Append($"{ticket.MaxPoints:F2}") .UnderlineStyle(UnderlineStyle.singleLine) .Alignment = Alignment.right; } docXdocument.Footers.Odd.InsertParagraph() .Append("Створено за допомогою SimplEx Program") .FontSize(10) .UnderlineStyle(UnderlineStyle.singleLine) .Alignment = Xceed.Document.NET.Alignment.right; docXdocument.Save(); } OpenWord(); }