Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 9638 |  Welcome, Guest!   Register  Login
 Home > Blogs > C# > Change Word Header & Footer Text and Image Information with C#, VB.NET ...
Lacy

Change Word Header & Footer Text and Image Information with C#, VB.NET

 Blog author: Lacy | Posted on: 5/30/2012 | Category: C# Blogs | Views: 6353 | Status: [Member] | Points: 75 | Alert Moderator   
Ads

Header and footer in Word show the additional information of this document. They are maybe not the main role but most times they are indispensible for the whole document. For example, the specialized books in a company always are printed a company logo on it to clearly tell users what the books come from. Using Spire.Doc, you can easily change word header & footer and header image with C#, VB.NET as well as add them.


How to change word header & footer and header image information with C#,VB.NET

Spire.Doc not only can change header & footer text information, but also can change its header image and set image format with C#, VB.NET. The whole task can be realized by the below four steps.

Step1. Create a new project

1.     Create a new project in Visual Studio, and Set the project Target framework in Property to be .NET Framework 2 or above.

2.      Add System.Drawing and Spire.Doc dll as reference in Project.

3.     Add the following using at the top of the method.

C#
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Collections;

VB.NET

Imports System.Drawing
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Collections

Step2. Load a word document from system

C# Code:
            Document doc = new Document();
            doc.LoadFromFile(@"E:\JaneEyre.docx", FileFormat.Docx);
 

VB.NET Code:
         Dim doc As New Document()
        doc.LoadFromFile("E:\JaneEyre.docx", FileFormat.Docx)


Step3. Change word header & footer and header image.

C# Code:
            HeaderFooter header = doc.Sections[0].HeadersFooters.Header;
            header.Paragraphs[0].Text = "Preview";
            Image logo = Image.FromFile(@"D:\E-ICEBLUE.png");
            header.Paragraphs[0].AppendPicture(logo).TextWrappingStyle = TextWrappingStyle.Tight;
            HeaderFooter footer = doc.Sections[0].HeadersFooters.Footer;
            footer.Paragraphs[0].Text = "Author: Charlotte Brontë";

VB.NET Code:
         Dim header As HeaderFooter = doc.Sections(0).HeadersFooters.Header
         header.Paragraphs(0).Text = "Preview"
         Dim logo As Image = Image.FromFile("D:\E-ICEBLUE.png")
         header.Paragraphs(0).AppendPicture(logo).TextWrappingStyle = TextWrappingStyle.Tight
         Dim footer As HeaderFooter = doc.Sections(0).HeadersFooters.Footer
         footer.Paragraphs(0).Text = "Author: Charlotte Brontë"

Step4. Save and launch the file

C# Code:
            doc.SaveToFile("Sample.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("Sample.docx");

VB.NET Code:
            doc.SaveToFile("Sample.docx", FileFormat.Docx)
            System.Diagnostics.Process.Start("Sample.docx")

Preview
 
                                                                  Original Header and Footer
  
                                                             Change Header & Footer Text and Image

More About Spire.Doc for .NET

Spire.Doc for .NET is an MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET. It supports C#, VB.NET, ASP.NET, ASP.NET MVC.



Found interesting? Add this to:


About Keating Arly

Experience:1 year(s)
Home page:http://www.e-iceblue.com
Member since:Tuesday, March 27, 2012
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/20/2013 1:31:03 AM