Пример #1
0
        /// <summary>
        /// Add objects from another document.
        /// </summary>
        public static void AddObjectsFromOtherDocument()
        {
            Console.WriteLine("\tAddObjectsFromOtherDocument()");

            // Load a template document.
            using (var templateDoc = DocX.Load(ParagraphSample.ParagraphSampleResourcesDirectory + @"Template.docx"))
            {
                // Create a document.
                using (var document = DocX.Create(ParagraphSample.ParagraphSampleOutputDirectory + @"AddObjectsFromOtherDocument.docx"))
                {
                    // Add a title.
                    document.InsertParagraph("Adding objects from another document").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                    // Insert a Paragraph into this document.
                    var p = document.InsertParagraph();

                    // Append some text and add formatting.
                    p.Append("This is a simple paragraph containing an image added from another document:")
                    .Font(new Xceed.Document.NET.Font("Arial"))
                    .FontSize(15)
                    .SpacingAfter(40d);

                    // Get the image from the other document.
                    var pictureToAdd = templateDoc.Pictures.FirstOrDefault();
                    // Add the image in the new document.
                    var newImage   = document.AddImage(pictureToAdd.Stream);
                    var newPicture = newImage.CreatePicture(pictureToAdd.Height, pictureToAdd.Width);
                    p.AppendPicture(newPicture);

                    // Insert a Paragraph into this document.
                    var p2 = document.InsertParagraph();

                    // Append some text and add formatting.
                    p2.Append("This is a simple paragraph added from another document, keeping its formatting:")
                    .Font(new Xceed.Document.NET.Font("Arial"))
                    .FontSize(15);

                    // Get the paragraph from the other document.
                    var paragraphToAdd = templateDoc.Paragraphs.FirstOrDefault(x => x.Text.Contains("Main"));
                    // Add the paragraph in the new document.
                    p2.InsertParagraphAfterSelf(paragraphToAdd).SpacingAfter(40d);

                    // Insert a Paragraph into this document.
                    var p3 = document.InsertParagraph();

                    // Append some text and add formatting.
                    p3.Append("This is a table added from another document, keeping its formatting:")
                    .Font(new Xceed.Document.NET.Font("Arial"))
                    .FontSize(15);

                    // Get the table from the other document.
                    var tableToAdd = templateDoc.Tables.FirstOrDefault();
                    // Add the table in the new document.
                    p3.InsertTableAfterSelf(tableToAdd);

                    document.Save();
                }
            }
        }
Пример #2
0
        public void CreateDocument()
        {
            DocX doc = DocX.Create(_settings.GetOutputFile("wfdoc"));

            CreateWorkflow(doc);

            doc.Save();
        }
Пример #3
0
 public void Save(string filename, string text)
 {
     using (DocX document = DocX.Create(filename))
     {
         document.InsertParagraph(text);
         document.Save();
     }
 }
Пример #4
0
        /// <summary>
        /// Сохраняет текст в файл word;
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="text"></param>
        public void SaveDocWord(string fileName, string text)
        {
            string pathFile = fileName;
            DocX   document = DocX.Create(pathFile);

            document.InsertParagraph(text);
            document.Save();
        }
Пример #5
0
        public void CreateDiagram(List <DiagramModel> list, string seriesname, string path)
        {
            DocX   document = DocX.Create(path);
            Series series   = GetSeries(list, seriesname);

            document.InsertChart(CreateBarChart(series));
            document.Save();
        }
Пример #6
0
        public void CreateDiagramInWord(List <String> Legend, List <int> Values, string path)
        {
            DocX   document = DocX.Create(path);
            Series series   = CreateSeries(Legend, Values);

            document.InsertChart(CreateBarChart(series));
            document.Save();
        }
Пример #7
0
 /// <summary>
 ///
 /// </summary>
 public WordHelper Create()
 {
     using (var ms = new MemoryStream())
     {
         _document = DocX.Create(ms);
     }
     return(this);
 }
Пример #8
0
        public void ThreeByThreeTable()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                var table = doc.AddTable(3);

                var row = table.AddRow();
                row.HeaderRow = true;

                row.Cells[0].Paragraphs[0].Append("Cell 1");
                row.Cells[1].Paragraphs[0].Append("Cell 2").SetAlignment(Align.Center);
                row.Cells[2].Paragraphs[0].Append("Cell 3").SetAlignment(Align.Right);

                row.Cells[0].Borders.Set(Units.HalfPt, BorderValue.Single);

                row.SetShading(ShadingPattern.Clear, "E7E6E6");

                row = table.AddRow();

                row.SetBorders(Units.HalfPt, BorderValue.Single);

                row.Cells[0].Paragraphs[0].Append("Cell 1");
                row.Cells[1].Paragraphs[0].Append("Cell 2").SetAlignment(Align.Center);
                row.Cells[2].Paragraphs[0].Append("Cell 3").SetAlignment(Align.Right);

                row = table.AddRow();

                row.Cells[0].Paragraphs[0].Append("Cell 1");
                row.Cells[1].Paragraphs[0].Append("Cell 2").SetAlignment(Align.Center);
                row.Cells[2].Paragraphs[0].Append("Cell 3").SetAlignment(Align.Right);

                row.Cells[1].Shading.Set(ShadingPattern.Clear, "F2F2F2");
                row.Cells[2].Shading.Set(ShadingPattern.Clear, "auto");

                var rows = table.Rows.ToList();

                for (int i = 0; i < rows.Count(); i++)
                {
                    row = rows[i];

                    row.Height           = Units.UHalfInch;
                    row.BreakAcrossPages = true;

                    for (int j = 0; j < row.Cells.Count(); j++)
                    {
                        var cell = row.Cells[j];

                        cell.SetVerticalAlignment(TableVerticalAlignment.Center);
                    }
                }

                Validate(doc);

                doc.Close();
            }
        }
Пример #9
0
        public static async Task Overview(Model model, BasinMapViewModel basin, String filename, bool detail = true)
        {
            try
            {
                var imageFile = Path.GetTempFileName() + ".png";
                await basin.Snapshot(imageFile);

                using (var document = DocX.Create(filename))
                {
                    var tp = document.InsertParagraph("Freshwater Health Index Assessment").Color(_blue).FontSize(16);
                    tp.Alignment = Alignment.center;
                    tp           = document.InsertParagraph($"{model.Attributes.Title} {model.Attributes.AssessmentYear}").FontSize(14);
                    tp.Alignment = Alignment.center;

                    // the picture
                    var image   = document.AddImage(imageFile);
                    var picture = image.CreatePicture();
                    var ip      = document.InsertParagraph();
                    ip.Alignment = Alignment.center;
                    ip.AppendPicture(picture);

                    document.InsertParagraph($"{DateTime.Now.ToLongDateString()}");
                    document.InsertParagraph(model.Attributes.Notes);

                    var level1 = 2;
                    foreach (var pillar in new[] { model.EcosystemVitality, model.EcosystemServices, model.Governance })
                    {
                        AddSection(document, pillar, detail, level1);
                        var level2 = 1;
                        foreach (var indicator in pillar.Children)
                        {
                            AddSection(document, indicator, detail, level1, level2);

                            var level3 = 1;
                            if (indicator.Children == null)
                            {
                                continue;
                            }
                            foreach (var sub in indicator.Children)
                            {
                                AddSection(document, sub, detail, level1, level2, level3);
                                level3++;
                            }

                            level2++;
                        }
                        level1++;
                    }

                    document.Save();
                    File.Delete(imageFile);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error producing document: {ex.Message}");
            }
        }
Пример #10
0
        /// <summary>
        /// Create a document and insert, remove and replace texts.
        /// </summary>
        public static void TextActions()
        {
            Console.WriteLine("\tTextActions()");

            // Create a new document.
            using (var document = DocX.Create(ParagraphSample.ParagraphSampleOutputDirectory + @"TextActions.docx"))
            {
                // Add a title
                document.InsertParagraph("Insert, remove and replace text").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Create a paragraph and insert text.
                var p1 = document.InsertParagraph("In this paragraph we insert a comma, a colon and ");
                // Add a comma at index 17.
                p1.InsertText(17, ",");
                // Add a colon at index of character 'd'.
                p1.InsertText(p1.Text.IndexOf("d") + 1, ": ");
                // Add "a name" at the end of p1.Text.
                p1.InsertText(p1.Text.Length, "a name.");

                p1.SpacingAfter(30);

                // Create a paragraph and insert text.
                var p2 = document.InsertParagraph("In this paragraph, we remove a mistaken word and a comma.");
                // Remove the word "mistaken".
                p2.RemoveText(31, 9);
                // Remove the comma sign.
                p2.RemoveText(p2.Text.IndexOf(","), 1);

                p2.SpacingAfter(30);

                // Create a paragraph and insert text.
                var p3 = document.InsertParagraph("In this paragraph, we replace an complex word with an easier one and spaces with hyphens.");
                // Replace the "complex" word with "easy" word.
                p3.ReplaceText("complex", "easy");
                // Replace the spaces with tabs
                p3.ReplaceText(" ", "--");

                p3.SpacingAfter(30);

                // Create a paragraph and insert text.
                var p4 = document.InsertParagraph("In this paragraph, we replace a word by using a handler: <COST>.");
                // Replace "<COST>" with "$13.95" using an handler
                p4.ReplaceText("<(.*?)>", ReplaceTextHandler, false, RegexOptions.IgnoreCase, null);

                p4.SpacingAfter(30);

                // Insert another Paragraph into this document.
                var p5 = document.InsertParagraph();

                // Append some text with track changes
                p5.Append("This is a paragraph where tracking of modifications is used.");
                p5.ReplaceText("modifications", "changes", true);

                // Save this document to disk.
                document.Save();
                Console.WriteLine("\tCreated: TextActions.docx\n");
            }
        }
Пример #11
0
 public GenerateDoc(string[][] data, int count)
 {
     Notifications.Notif.Info("Generowanie pliku z rozpiskami");
     document     = DocX.Create(@"Rozpiska.docx");
     membersCount = count;
     CreateHeader();
     CreateCopyright();
     GenerateClashes(data);
 }
Пример #12
0
        public static bool CreateTable(List <WordTableOption> options, string mainTitle, string fullPath)
        {
            try
            {
                //创建Word文档
                using (DocX document = DocX.Create(fullPath))
                {
                    //主标题
                    Paragraph mh = document.InsertParagraph();
                    mh.Alignment = Alignment.center;
                    mh.Append(mainTitle).Bold();
                    mh.LineSpacingBefore = 5f;
                    mh.LineSpacingAfter  = 5f;

                    options.ForEach(ele =>
                    {
                        //添加表格
                        Table table     = document.AddTable(ele.Rows.Count + 1, ele.Headers.Count);
                        table.Design    = TableDesign.TableGrid; //表格样式
                        table.Alignment = Alignment.center;      //设置表格居中
                        //填充头
                        for (int i = 0; i < ele.Headers.Count; i++)
                        {
                            var cell               = table.Rows[0].Cells[i];
                            cell.FillColor         = Color.Black;
                            cell.VerticalAlignment = VerticalAlignment.Center;
                            cell.Paragraphs[0].Append(ele.Headers[i]).Bold().Color(Color.White);
                        }
                        //填充主体
                        for (int i = 0; i < ele.Rows.Count; i++)
                        {
                            for (int j = 0; j < ele.Headers.Count; j++)
                            {
                                table.Rows[i + 1].Cells[j].Paragraphs[0].Append(ele.Rows[i][j]);
                            }
                        }

                        //做标题
                        Paragraph h = document.InsertParagraph();
                        h.Alignment = Alignment.center;
                        h.Append(ele.Title).Bold();
                        h.InsertTableAfterSelf(table);
                        h.LineSpacingBefore = 5f;
                        h.LineSpacingAfter  = 5f;
                    });
                    document.Save();
                }



                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #13
0
        /// <summary>
        /// Create a numbered and a bulleted lists with different listItem's levels.
        /// </summary>
        public static void AddList()
        {
            Console.WriteLine("\tAddList()");

            // Create a document.
            using (DocX document = DocX.Create(ListSample.ListSampleOutputDirectory + @"AddList.docx"))
            {
                // Add a title
                document.InsertParagraph("Adding lists into a document").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Add a numbered list where the first ListItem is starting with number 1.
                var numberedList = document.AddList("Berries", 0, ListItemType.Numbered, 1);
                // Add Sub-items(level 1) to the preceding ListItem.
                document.AddListItem(numberedList, "Strawberries", 1);
                document.AddListItem(numberedList, "Blueberries", 1);
                document.AddListItem(numberedList, "Raspberries", 1);
                // Add an item (level 0)
                document.AddListItem(numberedList, "Banana");
                // Add an item (level 0)
                document.AddListItem(numberedList, "Apple");
                // Add Sub-items(level 1) to the preceding ListItem.
                document.AddListItem(numberedList, "Red", 1);
                document.AddListItem(numberedList, "Green", 1);
                document.AddListItem(numberedList, "Yellow", 1);

                // Add a bulleted list with its first item.
                var bulletedList = document.AddList("Canada", 0, ListItemType.Bulleted);
                // Add Sub-items(level 1) to the preceding ListItem.
                document.AddListItem(bulletedList, "Toronto", 1);
                document.AddListItem(bulletedList, "Montreal", 1);
                // Add an item (level 0)
                document.AddListItem(bulletedList, "Brazil");
                // Add an item (level 0)
                document.AddListItem(bulletedList, "USA");
                // Add Sub-items(level 1) to the preceding ListItem.
                document.AddListItem(bulletedList, "New York", 1);
                // Add Sub-items(level 2) to the preceding ListItem.
                document.AddListItem(bulletedList, "Brooklyn", 2);
                document.AddListItem(bulletedList, "Manhattan", 2);
                document.AddListItem(bulletedList, "Los Angeles", 1);
                document.AddListItem(bulletedList, "Miami", 1);
                // Add an item (level 0)
                document.AddListItem(bulletedList, "France");
                // Add Sub-items(level 1) to the preceding ListItem.
                document.AddListItem(bulletedList, "Paris", 1);

                // Insert the lists into the document.
                document.InsertParagraph("This is a Numbered List:\n");
                document.InsertList(numberedList);
                document.InsertParagraph().SpacingAfter(40d);
                document.InsertParagraph("This is a Bulleted List:\n");
                document.InsertList(bulletedList, new Font("Cooper Black"), 15);

                document.Save();
                Console.WriteLine("\tCreated: AddList.docx\n");
            }
        }
Пример #14
0
        public void CreateDocument(string count)
        {
            string fileName = @"C:\Documents and Settings\HR\Employees per Department.docx";
            var    doc      = DocX.Create(fileName);

            doc.InsertParagraph(count);
            doc.Save();
            Process.Start("WINWORD.EXE", fileName);
        }
Пример #15
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            var companybik = Interaction.InputBox("Введите БИК компании: ");

            if (companybik == "")
            {
                return;
            }

            saveFileDialog1.FileName = "list";
            saveFileDialog1.ShowDialog();
            var path = saveFileDialog1.FileName;

            var conn = new MySqlConnection(Information.connString);

            conn.Open();

            DocX document = DocX.Create(path);

            document.InsertParagraph("Список должностей").Font("Times New Roman").FontSize(18).Alignment = Alignment.left;
            document.InsertParagraph();

            var count        = conn.QueryFirst <string> ($"select count(*) from position where company_id = {companybik}");
            var positionList = conn.Query <Position> ($"select name, payment, conditions, requirements from position where company_id = {companybik}").ToList();

            Table mainTable = document.AddTable(Convert.ToInt32(count) + 1, 4);

            mainTable.Alignment = Alignment.both;
            mainTable.AutoFit   = AutoFit.ColumnWidth;
            mainTable.SetWidthsPercentage(new[] { 25.0f, 25.0f, 25.0f, 25.0f });
            mainTable.Design = TableDesign.None;

            mainTable.Rows[0].Cells[0].Paragraphs[0].Append("Название должнолсти");
            mainTable.Rows[0].Cells[1].Paragraphs[0].Append("Оплата");
            mainTable.Rows[0].Cells[2].Paragraphs[0].Append("Условия");
            mainTable.Rows[0].Cells[3].Paragraphs[0].Append("Требования");

            for (int i = 0; i < Convert.ToInt32(count); i++)
            {
                mainTable.Rows[i + 1].Cells[0].Paragraphs[0].Append(positionList[i].name);
                mainTable.Rows[i + 1].Cells[1].Paragraphs[0].Append(positionList[i].payment);
                mainTable.Rows[i + 1].Cells[2].Paragraphs[0].Append(positionList[i].conditions);
                mainTable.Rows[i + 1].Cells[3].Paragraphs[0].Append(positionList[i].requirements);
            }

            document.InsertTable(mainTable);

            document.InsertParagraph();
            var phone = conn.QueryFirstOrDefault <string> ($"select phone from company where bik = {companybik}");

            document.InsertParagraph($"Звонить по телефону {phone}");

            document.Save();
            conn.Close();

            Process.Start(path);
        }
Пример #16
0
 // Сохранение в docx
 private void SaveToDocx(string text, string path)
 {
     using (DocX file = DocX.Create(path))
     {
         Paragraph p1 = file.InsertParagraph();
         p1.Append(text).Font("Times New Roman").FontSize(14);
         file.Save();
     }
 }
Пример #17
0
        public void TestMethod()
        {
            using (var doc = DocX.Create(@"HelloWorld.docx"))
            {
                doc.Save();
            }

            DocX document = DocX.Load(@"HelloWorld.docx");
        }
Пример #18
0
        public WordDocumentGenerator(string fileName)
        {
            this.FileName = fileName;
            string path = Path.Combine(Environment.CurrentDirectory, fileName);

            this.doc = DocX.Create(path);
            this.doc.Save();
            Console.WriteLine(path);
        }
Пример #19
0
        private void btkKilometri_Click(object sender, EventArgs e)
        {
            List <Sport> sport = new List <Sport>();

            sport = Info();
            //Location Path
            string fileName = @"Info.docx";

            var doc = DocX.Create(fileName);
            //Formatting Title
            Formatting titleFormat = new Formatting();

            //Specify font family
            titleFormat.FontFamily = new Font("Batang");
            //Specify font size
            titleFormat.Size           = 18;
            titleFormat.Position       = 40;
            titleFormat.FontColor      = System.Drawing.Color.Orange;
            titleFormat.UnderlineColor = System.Drawing.Color.Gray;
            titleFormat.Italic         = true;
            //Formatting Text Paragraph
            Formatting textParagraphFormat = new Formatting();

            //font family
            textParagraphFormat.FontFamily = new Font("Century Gothic");
            //font size
            textParagraphFormat.Size = 10;
            //Spaces between characters
            textParagraphFormat.Spacing = 2;

            int count = sport.Count;
            //Create Table with 2 rows and 4 columns.
            Table t = doc.AddTable(count + 3, 4);

            t.Alignment = Alignment.center;
            t.Design    = TableDesign.ColorfulList;
            //Fill cells by adding text.
            t.Rows[0].Cells[0].Paragraphs.First().Append("Kolesar");
            t.Rows[0].Cells[1].Paragraphs.First().Append("Total distance");
            t.Rows[0].Cells[2].Paragraphs.First().Append("Total calories");
            t.Rows[0].Cells[3].Paragraphs.First().Append("Total time");

            int stevec = 1;

            foreach (var item in sport)
            {
                t.Rows[stevec].Cells[0].Paragraphs.First().Append(stevec.ToString());
                t.Rows[stevec].Cells[1].Paragraphs.First().Append(item.Stevilo_prevozenih_km);
                t.Rows[stevec].Cells[2].Paragraphs.First().Append(item.Porabljene_kalorije);
                t.Rows[stevec].Cells[3].Paragraphs.First().Append(item.Trajanje_aktivnosti);
                stevec++;
            }

            doc.InsertTable(t);
            doc.Save();
            Process.Start("WINWORD.EXE", fileName);
        }
Пример #20
0
        public void CreateDocument()
        {
            string fileName = @"C:\Documents and Settings\HR\Birthdays.docx";
            var    doc      = DocX.Create(fileName);

            doc.InsertParagraph(string.Join(" \n", birthdays));
            doc.Save();
            Process.Start("WINWORD.EXE", fileName);
        }
Пример #21
0
        static void Main(string[] args)
        {
            var document = DocX.Create("MyReport.docx");

            document.InsertParagraph("this is an amazing report");
            document.InsertParagraph($"Report generated by <<authour>> at {DateTime.Now}");
            document.Save();
            Process.Start("WINWORD.EXE", "MyReport.docx");
        }
Пример #22
0
        public static void Diagramma(Info info)
        {
            string pathDocument = info.FileName;
            DocX   document     = DocX.Create(pathDocument);

            document.InsertChart(CreatePieChart(info));
            document.InsertChart(CreateBarChart(info));
            document.Save();
        }
Пример #23
0
        private void SaveToNewFile()
        {
            try
            {
                string fileName = !string.IsNullOrEmpty(_FileName) ? _FileName + ".docx" : DateTime.Now.ToString("dd-MM-yyyy") + ".docx";

                if (!IsFileLocked(WordFileDirectory + fileName))
                {
                    sc = new ScreenCapture();

                    // capture entire screen, and save it to a file
                    System.Drawing.Image img1 = sc.CaptureScreen();

                    // capture this window, and save it;
                    //sc.CaptureWindowToFile(this.Handle, Guid.NewGuid()+".gif", ImageFormat.Gif);
                    img1.Save("Screenshot" + ".jpg", ImageFormat.Jpeg);

                    if (!Directory.Exists(WordFileDirectory))
                    {
                        Directory.CreateDirectory(WordFileDirectory);
                    }

                    if (!File.Exists(WordFileDirectory + fileName))
                    {
                        var docCreate = DocX.Create(WordFileDirectory + fileName);
                        docCreate.Save();
                    }
                    var     docload = DocX.Load(WordFileDirectory + fileName);
                    Image   img     = docload.AddImage("Screenshot.jpg");
                    Picture p       = img.CreatePicture();
                    p.Width  = 690;
                    p.Height = 365;

                    Paragraph par = docload.InsertParagraph(Convert.ToString(" "));
                    par.AppendPicture(p);
                    docload.Save();
                }
                else
                {
                    MessageBox.Show("The action can't be completed because the file is open in System.", "Error", MessageBoxButtons.OK);
                }
            }
            catch (IOException ex)
            {
                flag = true;
                MessageBox.Show("The action can't be completed because the file is open in System.", "Error", MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                flag = true;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }
            finally
            {
                ThreadStart();
            }
        }
Пример #24
0
        public static void CreateTestReport(Patient patient, MedicalTest test, string file_path)
        {
            if (file_path == null)
            {
                return;
            }
            Type test_type = test.GetType();

            using (DocX document = DocX.Create(file_path))
            {
                Novacode.Paragraph header = document.InsertParagraph(
                    //selected_procedure.ProcedureType.First().ToString().ToUpper() + String.Join("", selected_procedure.ProcedureType.Skip(1)).ToLower(),
                    test_type.GetCustomAttribute <DisplayNameAttribute>().DisplayName,
                    false,
                    new Formatting()
                {
                    FontFamily = new System.Drawing.FontFamily("Times New Roman"),
                    Size       = 16D
                }
                    );
                header.Alignment = Alignment.center;
                header.Bold();
                document.InsertParagraph(" ");
                Novacode.Table patient_info = document.AddTable(5, 2);
                patient_info.Rows[0].Cells[0].Paragraphs.First().Append("ФИО пациента").Bold();
                patient_info.Rows[0].Cells[1].Paragraphs.First().Append(patient.LastName + " " + patient.FirstName + " " + patient.Patronym);
                patient_info.Rows[1].Cells[0].Paragraphs.First().Append("Пол").Bold();
                patient_info.Rows[1].Cells[1].Paragraphs.First().Append(patient.Sex == Sex.мужской ? "мужской" : "женский");
                patient_info.Rows[2].Cells[0].Paragraphs.First().Append("Дата рождения").Bold();
                patient_info.Rows[2].Cells[1].Paragraphs.First().Append(patient.Birthdate.ToShortDateString());
                patient_info.Rows[3].Cells[0].Paragraphs.First().Append("Адрес проживания").Bold();
                patient_info.Rows[3].Cells[1].Paragraphs.First().Append(
                    patient.PostIndex + ", " + patient.Country + ", " + patient.Region +
                    ", " + patient.City + ", " + patient.Address
                    );
                patient_info.Rows[4].Cells[0].Paragraphs.First().Append("Номер карты").Bold();
                patient_info.Rows[4].Cells[1].Paragraphs.First().Append(patient.CardNumber.ToString());
                patient_info.Alignment = Alignment.left;
                patient_info.AutoFit   = AutoFit.Window;
                PropertyInfo[] indicators = test_type.GetProperties().Where(x => x.IsDefined(typeof(TestInfo))).ToArray();
                Novacode.Table test_info  = document.AddTable(indicators.Count(), 2);
                int            k          = 0;
                foreach (var indicator in indicators)
                {
                    test_info.Rows[k].Cells[0].Paragraphs.First().Append(indicator.GetCustomAttribute <TestInfo>().DisplayName);
                    object property_value = indicator.GetValue(test);
                    test_info.Rows[k].Cells[1].Paragraphs.First().Append(property_value != null ? property_value.ToString() : "");
                    k++;
                }
                test_info.Alignment = Alignment.left;
                test_info.AutoFit   = AutoFit.Window;
                document.InsertTable(patient_info);
                document.InsertParagraph(" ");
                document.InsertTable(test_info);
                document.Save();
            }
        }
Пример #25
0
        /// <summary>
        /// Add a Table in a document where its columns will have a specific width. In addition,
        /// the left margin of the row cells will be removed for all rows except the first.
        /// Finally, a blank border will be set for the table's top and bottom borders.
        /// </summary>
        public static void ColumnsWidth()
        {
            Console.WriteLine("\tColumnsWidth()");

            // Create a document
            using (DocX document = DocX.Create(TableSample.TableSampleOutputDirectory + @"ColumnsWidth.docx"))
            {
                // Add a title
                document.InsertParagraph("Columns width").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Insert a title paragraph.
                var p = document.InsertParagraph("In the following table, the cell's left margin has been removed for rows 2-6 as well as the top/bottom table's borders.").Bold();
                p.Alignment = Alignment.center;
                p.SpacingAfter(40d);

                // Add a table in a document of 1 row and 3 columns.
                var columnWidths = new float[] { 100f, 300f, 200f };
                var t            = document.InsertTable(1, columnWidths.Length);

                // Set the table's column width and background
                t.SetWidths(columnWidths);
                t.Design  = TableDesign.TableGrid;
                t.AutoFit = AutoFit.Contents;

                var row = t.Rows.First();

                // Fill in the columns of the first row in the table.
                for (int i = 0; i < row.Cells.Count; ++i)
                {
                    row.Cells[i].Paragraphs.First().Append("Data " + i);
                }

                // Add rows in the table.
                for (int i = 0; i < 5; i++)
                {
                    var newRow = t.InsertRow();

                    // Fill in the columns of the new rows.
                    for (int j = 0; j < newRow.Cells.Count; ++j)
                    {
                        var newCell = newRow.Cells[j];
                        newCell.Paragraphs.First().Append("Data " + i);
                        // Remove the left margin of the new cells.
                        newCell.MarginLeft = 0;
                    }
                }

                // Set a blank border for the table's top/bottom borders.
                var blankBorder = new Border(BorderStyle.Tcbs_none, 0, 0, Color.White);
                t.SetBorder(TableBorderType.Bottom, blankBorder);
                t.SetBorder(TableBorderType.Top, blankBorder);

                document.Save();
                Console.WriteLine("\tCreated: ColumnsWidth.docx\n");
            }
        }
Пример #26
0
        public FileResult OnGetCreateDocx(string keyword, string words, string wordsForStudent, string fillwordString, string fillwordFullString, string sudokuString, string crosswordString, string chessString, string chessWord)
        {
            List <char>   lettersArray         = new List <char>(keyword.Length);
            List <string> wordsArray           = CreateWordList(words);
            List <string> wordsArrayForStudent = CreateWordList(wordsForStudent);

            for (int i = 0; i < keyword.Length; i++)
            {
                if (!lettersArray.Contains(keyword[i]))
                {
                    lettersArray.Add(keyword[i]);
                }
            }


            MemoryStream memoryStream = new MemoryStream();


            System.Drawing.Image imgForTeacher = PageForTeacher(keyword, wordsArray, lettersArray, fillwordString, sudokuString, crosswordString, chessString, chessWord);
            System.Drawing.Image imgForStudent = PageForStudent(keyword, wordsArrayForStudent, lettersArray, fillwordFullString, sudokuString, crosswordString, chessString, chessWord);

            Stream imageTeacherStream = new MemoryStream();
            Stream imageStudentStream = new MemoryStream();

            imgForTeacher.Save(imageTeacherStream, System.Drawing.Imaging.ImageFormat.Png);
            imgForStudent.Save(imageStudentStream, System.Drawing.Imaging.ImageFormat.Png);

            imageTeacherStream.Seek(0, SeekOrigin.Begin);
            imageStudentStream.Seek(0, SeekOrigin.Begin);

            DocX document = DocX.Create(memoryStream);

            document.MarginTop  = 6f;
            document.MarginLeft = 6f;

            var streamImageTeacher = document.AddImage(imageTeacherStream);
            var streamImageStudent = document.AddImage(imageStudentStream);

            var pictureStreamTeacher = streamImageTeacher.CreatePicture(1096, 775);
            var pictureStreamStudent = streamImageStudent.CreatePicture(1096, 775);

            var p3 = document.InsertParagraph();

            p3.AppendPicture(pictureStreamTeacher).Alignment = Alignment.center;
            p3.AppendPicture(pictureStreamStudent).Alignment = Alignment.center;

            document.Save();


            memoryStream.Seek(0, SeekOrigin.Begin);

            string file_type = "application/docx";
            string file_name = "file.docx";

            return(File(memoryStream, file_type, file_name));
        }
Пример #27
0
 public void Bookmark_should_reference_paragraph()
 {
     using (var doc = DocX.Create(""))
     {
         var paragraph = doc.InsertParagraph("A paragraph");
         paragraph.AppendBookmark("bookmark");
         var bookmarks = paragraph.GetBookmarks();
         Assert.AreEqual(paragraph, bookmarks.First().Paragraph);
     }
 }
Пример #28
0
 public void Bookmark_should_be_appended()
 {
     using (var doc = DocX.Create(""))
     {
         var paragraph = doc.InsertParagraph("A paragraph");
         paragraph.AppendBookmark("bookmark");
         var bookmarks = paragraph.GetBookmarks();
         Assert.AreEqual(1, bookmarks.Count());
     }
 }
Пример #29
0
        public void testCreateDocument()
        {
            DocX document = DocX.Create("Indentation.docx");

            // Add a title.
            document.InsertParagraph("Paragraph indentation").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;
            // Set a smaller page width. (in points)
            document.PageWidth = 250f;
            document.Save();
        }
Пример #30
0
 public void Bookmark_should_be_named_correctly()
 {
     using (var doc = DocX.Create(""))
     {
         var paragraph = doc.InsertParagraph("A paragraph");
         paragraph.AppendBookmark("bookmark");
         var bookmarks = paragraph.GetBookmarks();
         Assert.AreEqual("bookmark", bookmarks.First().Name);
     }
 }