Use C # to implement a method for inserting header footers in Word

Source: Internet
Author: User

The operation for word is a lot of the functions of the program, this article is to demonstrate the use of C # Implementation of the method of inserting headers and footers in Word, for your reference, the specific method is as follows:


First, insert the footer method:

public void Insertfooter (string footer) {  if (ActiveWindow.ActivePane.View.Type = = Wdviewtype.wdnormalview | |    ActiveWindow.ActivePane.View.Type = = Wdviewtype.wdoutlineview)  {    ActiveWindow.ActivePane.View.Type = Wdviewtype.wdprintview;  }  ActiveWindow.View.SeekView = Wdseekview.wdseekcurrentpagefooter;  This. Application.Selection.HeaderFooter.LinkToPrevious = false;  This. Application.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = Wdparagraphalignment.wdalignparagraphcenter ;  ActiveWindow.ActivePane.Selection.InsertAfter (footer);  Jump out of header footer settings  ActiveWindow.View.SeekView = wdseekview.wdseekmaindocument;}


Ii. methods on MSDN:

foreach (Word.section wordsection in this. Application.ActiveDocument.Sections) {    Word.Range footerrange = wordsection.footers[ Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]. Range;    FooterRange.Font.ColorIndex = Word.WdColorIndex.wdDarkRed;    FooterRange.Font.Size =;    Footerrange.text = "Footer Footer";} foreach (word.section. Application.ActiveDocument.Sections) {    word.range headerrange = section. Headers[word.wdheaderfooterindex.wdheaderfooterprimary]. Range;    HEADERRANGE.FIELDS.ADD (Headerrange, Word.WdFieldType.wdFieldPage);    HeaderRange.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;}

I hope the example of this article can help you in C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
Use C # to implement a method for inserting header footers in Word

This address: http://www.paobuke.com/develop/c-develop/pbk23632.html






Related Content C # Seven classic sorting algorithm series (UP) C # Add a watermark to a PDF file C # implement file upload and download features example C # DataTable Compute Method Usage Highlights (numeric/string/operator/table Operations)
C # Programming Self-taught data types and variables a C # method of sending data to clipboard and fetching data from clipboard C # custom serialization ISerializable Implementation Method C # The difference analysis between IS and as

Use C # to implement a method for inserting header footers in Word

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.