Spire.Doc

With the help of Spire.Doc for .NET, developers can easily set bullet style for the existing word documents via invoke p.ListFormat.ApplyBulletStyle() method to format. This article will show you how to convert HTML list into word and set the bullet style for the word list in C#.

Firstly, please view the effective screenshot for the result word document:

How to set word bullet style by appending the HTML code in C#

Here comes to the steps:

Step 1: Create a new document and add a section to the document.

Document document = new Document();
Section section=document.AddSection();

Step 2: Add word list to the paragraph by appending HTML.

Paragraph paragraph = section.AddParagraph();
paragraph.AppendHTML("<ol><li>Version 1</li><li>Version 2</li><li>Version 3</li></ol>");

Step 3: Set the bullet style for the paragraph.

foreach (Paragraph p in section.Paragraphs)
{
 p.ApplyStyle(BuiltinStyle.Heading2);
 p.ListFormat.CurrentListLevel.NumberPosition = 20;
 p.ListFormat.CurrentListLevel.TextPosition = 30;
 }

Step 4: Save the document to file

document.SaveToFile("result.docx",FileFormat.Docx);

Full codes:

static void Main(string[] args)
{

    Document document = new Document();
    Section section = document.AddSection();
    Paragraph paragraph = section.AddParagraph();
    paragraph.AppendHTML("<ol><li>Version 1</li><li>Version 2</li><li>Version 3</li></ol>");


    foreach (Paragraph p in section.Paragraphs)
    {

        p.ApplyStyle(BuiltinStyle.Heading2);

        p.ListFormat.CurrentListLevel.NumberPosition = 20;

        p.ListFormat.CurrentListLevel.TextPosition = 30;

    }

        document.SaveToFile("result.docx",FileFormat.Docx);


}

Spire.Doc can help developers to create word table with data and format cells easily and it also supports to add text watermark into the word documents. This article will show you how to create a vertical table at one side of the word document, which looks like the vertical watermark in the word document.

Firstly, please check the effective screenshot of the vertical table at the right of the word document added by Spire.Doc:

How to create vertical table at one side of the word document

Here comes to the steps of how to create vertical table in C#.

Step 1: Create a new document and add a section to the document.

Document document = new Document();
Section section=document.AddSection();

Step 2: Add a table with rows and columns and set the text for the table.

Table table = section.AddTable();
table.ResetCells(1, 1);
TableCell cell = table.Rows[0].Cells[0];
table.Rows[0].Height = 150;
cell.AddParagraph().AppendText("Draft copy in vertical style");

Step 3: Set the TextDirection for the table to RightToLeftRotated.

cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;

Step 4: Set the table format.

table.TableFormat.WrapTextAround = true;
table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Page;
table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;
table.TableFormat.Positioning.HorizPosition = section.PageSetup.PageSize.Width- table.Width;
table.TableFormat.Positioning.VertPosition = 200;

Step 5: Save the document to file.

document.SaveToFile("result.docx");

Full codes in C#:

using Spire.Doc;
using Spire.Doc.Documents;

namespace CreateVerticalTable
{
    class Program
    {
        static void Main(string[] args)
        {

            Document document = new Document();
            Section section=document.AddSection();
            Table table = section.AddTable();
            table.ResetCells(1, 1);
            TableCell cell = table.Rows[0].Cells[0];
            table.Rows[0].Height = 150;
            cell.AddParagraph().AppendText("Draft copy in vertical style");
            cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;
            table.TableFormat.WrapTextAround = true;
            table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Page;
            table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;
            table.TableFormat.Positioning.HorizPosition = section.PageSetup.PageSize.Width- table.Width;
            table.TableFormat.Positioning.VertPosition = 200;

            document.SaveToFile("result.docx");

        }
    }
}

Page number is one of the formats of header and footer. It gives the total pages of a document and it is convenient for readers to index. Spire.Doc supports to add text and image header and footers. This tutorial will guide you how to add the page number on the header/footer of a document in C#.

Spire.Doc offers HeaderFooter class to set header or footer for word document. Then, invoke header/footer.AddParagraph() method to add header/footer paragraph and add contents by invoking paragraph.AppendText method. Here comes to the code snippet of how to add the page number for word documents.

Step 1: Create a new document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx");

Step 2: Create footer for the first section and add a paragraph for the footer.

HeaderFooter footer = doc.Sections[0].HeadersFooters.Footer;
Paragraph footerParagraph = footer.AddParagraph();

Step 3: Add the page number to the footer and set the alignment for the paragraph.

footerParagraph.AppendField("page number", FieldType.FieldPage);
footerParagraph.AppendText(" of ");
footerParagraph.AppendField("number of pages", FieldType.FieldNumPages);
footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right;

Step 4: Save the document to file.

doc.SaveToFile("Add.docx", FileFormat.Docx);

Effective screenshot:

How to add the page number on the header/footer of a document

Full codes:

namespace AddPagenumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx");
            HeaderFooter footer = doc.Sections[0].HeadersFooters.Footer;
            Paragraph footerParagraph = footer.AddParagraph();
            footerParagraph.AppendField("page number", FieldType.FieldPage);
            footerParagraph.AppendText(" of ");
            footerParagraph.AppendField("number of pages", FieldType.FieldNumPages);
            footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right;
            doc.SaveToFile("Add.docx", FileFormat.Docx);

        }
    }
}
Page 1 of 27