DocX v1.0.0.9 makes Paragraph creation even easier. The original idea of using Append in this manor came from a DocX user Morten Bjerre. Once again Morten I would like to say thank you for your contribution.
The below code creates a document with the following content.
- A Picture
- A Hyperlink
- Different fonts
- Different text styles
I hope you will agree that Append() and its variants [AppendLine(), AppendPicture() and AppendHyperlink()] make the creation of Paragraphs flow in a very fluid manor.
The below code creates the following output.
- // Create a document.
- using (DocX document = DocX.Create("Test.docx"))
- {
- // Add a hyperlink into the document.
- Hyperlink link = document.AddHyperlink("link", new Uri("http://www.google.com"));
- // Add a Table into the document.
- Table table = document.AddTable(2, 2);
- table.Design = TableDesign.ColorfulGridAccent2;
- table.Alignment = Alignment.center;
- table.Rows[0].Cells[0].Paragraphs[0].Append("3");
- table.Rows[0].Cells[1].Paragraphs[0].Append("1");
- table.Rows[1].Cells[0].Paragraphs[0].Append("4");
- table.Rows[1].Cells[1].Paragraphs[0].Append("1");
- // Add an image into the document.
- Novacode.Image image = document.AddImage("Image.jpg");
- // Create a picture (A custom view of an Image).
- Picture picture = image.CreatePicture();
- picture.Rotation = 10;
- picture.SetPictureShape(BasicShapes.cube);
- // Insert a new Paragraph into the document.
- Paragraph title = document.InsertParagraph().Append("Test").FontSize(20).Font(new FontFamily("Comic Sans MS"));
- title.Alignment = Alignment.center;
- // Insert a new Paragraph into the document.
- Paragraph p1 = document.InsertParagraph();
- // Append content to the Paragraph
- p1.AppendLine("This line contains a ").Append("bold").Bold().Append(" word.");
- p1.AppendLine("Here is a cool ").AppendHyperlink(link).Append(".");
- p1.AppendLine();
- p1.AppendLine("Check out this picture ").AppendPicture(picture).Append(" its funky don't you think?");
- p1.AppendLine();
- p1.AppendLine("Can you check this Table of figures for me?");
- p1.AppendLine();
- // Insert the Table after Paragraph 1.
- p1.InsertTableAfterSelf(table);
- // Insert a new Paragraph into the document.
- Paragraph p2 = document.InsertParagraph();
- // Append content to the Paragraph.
- p2.AppendLine("Is it correct?");
- // Save this document.
- document.Save();
- }
If you would like to request a new feature, report a bug or just say hi, send me an email at coffey.cathal@gmail.com
Happy coding,
Cathal
Future
As always, I offer this code to you for free. I am however a student and if you would like to help me pay of some of my student debt , you can make a donation to DocX via paypal.
I think there's a bug with the RowCount and ColumnCount property. After creating the table, I tried to iterate through the Row & Column collection, but if you rely on the count properties, they only return 0.
ReplyDeleteTaking a gander at the best school paper composing administration at exposition is precisely and explore the details what you require on the grounds that our surveys will assist you with finding a modest and dependable written work benefit that won't let you down!
ReplyDelete