Spire.Doc
Tuesday, 04 December 2012 06:40

Insert Endnote in Word in C#, VB.NET

Written by support iceblue

Word endnote is often put in the end of the document, which presents references of referred words/sentences/paragraphs. It includes two parts, marker and text. Marker can be customized or ordered automatically (i, ii, iii…). When one endnote is added, deleted or moved, the marker will be reordered automatically.

Spire.Doc for .NET, a stand-alone component used to manipulate Word document for .NET applications, enables users to insert endnote in Word by using C#, VB.NET. This guide introduces a method about how to realize this function via Spire.Doc for .NET.

Because endnote is included in footnote class, so invoke p.AppendFootnote(FootnoteType.Endnote) method to insert endnote. Then, use endnote.TextBody.AddParagraph().AppendText(string) method to add text and set CharacterFormat and MarkerCharacterFormat properties for endnote text and marker format. Download and install Spire.Doc for .NET and use the following code to insert endnote in Word.

Insert Word Endnote

[C#]
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace WordEndnote
{
    class InsertEndnote
    {
        static void Main(string[] args)
        {
            //Load Document
            Document doc = new Document();
            doc.LoadFromFile(@"E:\Work\Documents\WordDocuments\Antarctic.docx", FileFormat.Docx);
            Section s = doc.Sections[0];
            Paragraph p = s.Paragraphs[3];

            //Add Footnote
            Footnote endnote = p.AppendFootnote(FootnoteType.Endnote);

            //Append Text
            TextRange text = endnote.TextBody.AddParagraph().AppendText("Reference: Wikipedia");

            //Text Format
            text.CharacterFormat.FontName = "Impact";
            text.CharacterFormat.FontSize = 14;
            text.CharacterFormat.TextColor = Color.DarkOrange;

            //Marker Format
            endnote.MarkerCharacterFormat.FontName = "Calibri";
            endnote.MarkerCharacterFormat.FontSize = 14;
            endnote.MarkerCharacterFormat.TextColor = Color.DarkBlue;

            //Save and Launch
            doc.SaveToFile("Endnote.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("Endnote.docx");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace WordEndnote
    Friend Class InsertEndnote
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim doc As New Document()
            doc.LoadFromFile("E:\Work\Documents\WordDocuments\Antarctic.docx", FileFormat.Docx)
            Dim s As Section = doc.Sections(0)
            Dim p As Paragraph = s.Paragraphs(3)

            'Add Footnote
            Dim endnote As Footnote = p.AppendFootnote(FootnoteType.Endnote)

            'Append Text
            Dim text As TextRange = endnote.TextBody.AddParagraph().AppendText("Reference: Wikipedia")

            'Text Format
            text.CharacterFormat.FontName = "Impact"
            text.CharacterFormat.FontSize = 14
            text.CharacterFormat.TextColor = Color.DarkOrange

            'Marker Format
            endnote.MarkerCharacterFormat.FontName = "Calibri"
            endnote.MarkerCharacterFormat.FontSize = 14
            endnote.MarkerCharacterFormat.TextColor = Color.DarkBlue

            'Save and Launch
            doc.SaveToFile("Endnote.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("Endnote.docx")
        End Sub
    End Class
End Namespace

Spire.Doc is a Microsoft Word component, which enables users to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document in WPF, .NET and Silverlight.

Tuesday, 04 December 2012 06:19

How to Set Word Bullet Style in C#, VB.NET

Written by support iceblue

Word Bullet can format several paragraphs as a list. It can emphasize paragraphs with bullets and attract readers’ attention. With bullets, the listed paragraphs will be indented automatically with symbols, which can be point, number or other customized symbols (such as small star, triangle, arrow etc.).

Spire.Doc for .NET, an easy-to-use component to operate Word document for developers' .NET applications, enables users to set Word bullet style for paragraphs in document. This guide will focus on how to realize this function by using C#, VB.NET via Spire.Doc for .NET.

After loading the document, get paragraphs which you want to set bullet style and then invoke p.ListFormat.ApplyBulletStyle() method to format. Also, you can set NumberPosition property of current list to get spacing between bullet symbol and paragraph contents. Download and Install Spire.Doc for .NET. And then use the following code to set Word bullet style.

Word Paragraph Bullets

[C#]
using Spire.Doc;
using Spire.Doc.Documents;

namespace WordBullets
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load Document
            Document doc = new Document();
            doc.LoadFromFile(@"E:\References.docx");

            //Set Bullet Style
            Section s = doc.Sections[0];

            for (int i = 1; i< s.Paragraphs.Count; i++)
            {
                Paragraph p = s.Paragraphs[i];
                p.ListFormat.ApplyBulletStyle();
                p.ListFormat.CurrentListLevel.NumberPosition = -10;
            }

            //Save and Launch
            doc.SaveToFile("sample.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("sample.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordBullets
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim doc As New Document()
            doc.LoadFromFile("E:\References.docx")

            'Set Bullet Style
            Dim s As Section = doc.Sections(0)

            For i As Integer = 1 To s.Paragraphs.Count - 1
                Dim p As Paragraph = s.Paragraphs(i)
                p.ListFormat.ApplyBulletStyle()
                p.ListFormat.CurrentListLevel.NumberPosition = -10
            Next i

            'Save and Launch
            doc.SaveToFile("sample.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("sample.docx")
        End Sub
    End Class
End Namespace

Spire.Doc is a stand-alone component, enabling developers/programmers to generate, open, write, edit and save Word document in WPF, .NET and Silverlight without Microsoft Word installed on system.

Thursday, 29 November 2012 02:49

Remove Bookmark in C#, VB.NET

Written by support iceblue

Word bookmark is convenient for users to fix location of specified text, sentence or paragraph. The bookmark can be inserted any location of document. Also, it can be named or deleted. The following screenshot presents result document with bookmark.

Remove Word Bookmark

Spire.Doc for .NET, the professional .NET Word component to manipulate Word document, enables users to remove Word bookmark by using C#, VB.NET. Invoke doc.Bookmarks.RemoveAt(int index) method to remove bookmarks. Download and install Spire.Doc for .NET. Then use the following code to remove:

Remove Word Bookmark

[C#]
using Spire.Doc;

namespace Removing
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load Document
            Document doc = new Document();
            doc.LoadFromFile(@"E:\Work\Documents\WordDocuments\Blues Introduction.docx");

            //Remove Bookmark
            doc.Bookmarks.RemoveAt(0);

            //Save and Launch
            doc.SaveToFile("Remove Bookmark.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("Remove Bookmark.docx");
        }
    }
}
[VB.NET]
Imports Spire.Doc

Namespace Removing
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Load Document
            Dim doc As New Document()
            doc.LoadFromFile("E:\Work\Documents\WordDocuments\Blues Introduction.docx")

            'Remove Bookmark
            doc.Bookmarks.RemoveAt(0)

            'Save and Launch
            doc.SaveToFile("Remove Bookmark.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("Remove Bookmark.docx")
        End Sub
    End Class
End Namespace

Spire.Doc, a professional Word component, enables developers/programmers to operate Word document, for example, generating, opening, saving and modifying on .NET, WPF and Silverlight applications