C # Word operation knowledge summary 2

Source: Internet
Author: User

Delete the horizontal line of the header

Http://club.excelhome.net/viewthread.php? Tid = 450171 & Highlight = % C9 % be % B3 % FD

// Delete content
Odoc. Sections [1]. headers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. Cut ();
// Delete the odoc. Sections [1]. headers [word. wdheaderfooterindex. Handler]. range. Borders [word. wdbordertype. wdborderbottom]. linestyle = word. wdlinestyle. wdlinestylenone;

 

 

This article mainly involves the page number of a section, and how to make the page number of a section start from 1, instead of following the page number of the entire document.

In word 2003, the steps to achieve this effect are as follows:

(1) Insert a subscriber

(2) Open the header and footer view and cancel "link to previous page"

 

Following this idea, we also need to perform similar operations in the program.

(1) Insert a subscriber

Word. Section mysec = odoc. Sections. Add (ref missing, ref missing );

(2) Insert the header and footer

(3) Cancel "link to previous page"

(4) Insert page number

Public void setsections (INT secnum) {// for a specific instance (section 3), which needs to be modified <br/> // odoc. sections [secnum]. pagesetup. differentfirstpageheaderfooter =-1; // the first page of the section is different from other pages of the Section (true) <br/> // odoc. sections [secnum]. headers [word. wdheaderfooterindex. wdheaderfooterfirstpage]. range. TEXT = "header on the first page"; <br/> // odoc. sections [secnum]. headers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. TEXT = "other page headers"; <br/> // odoc. sections [secnum]. footers [word. wdheaderfooterindex. wdheaderfooterfirstpage]. range. TEXT = "footer on the first page"; <br/> // odoc. sections [secnum]. footers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. TEXT = "footer of other pages"; <br/> // odoc. sections [secnum]. headers [word. wdheaderfooterindex. wdheaderfooterfirstpage]. linktoprevious = false; // unlink to the previous page <br/> odoc. sections [secnum]. footers [word. wdheaderfooterindex. wdheaderfooterprimary]. linktoprevious = false; // header <br/> odoc. sections [secnum]. headers [word. wdheaderfooterindex. wdheaderfooterprimary]. linktoprevious = false; // footer <br/> odoc. sections [secnum]. headers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. TEXT = "header content"; <br/> // odoc. sections [secnum]. footers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. TEXT = "footer content"; </P> <p> oword. activewindow. view. seekview = Microsoft. office. interOP. word. wdseekview. wdseekcurrentpagefooter; // go to the footer view <br/> // oword. selection. paragraphs. alignment = word. wdparagraphalignment. wdalignparagraphcenter; // center the entire footer <br/> Object page = Microsoft. office. interOP. word. wdfieldtype. wdfieldpage; // the current page number <br/> oword. selection. headerfooter. pagenumbers. restartnumberingatsection = true; // reset the starting page number <br/> oword. selection. headerfooter. pagenumbers. startingnumber = 1; // set to 1 <br/> oword. selection. fields. add (oword. selection. range, ref page, ref missing, ref missing); // Add the page number field <br/> Object alignment = Microsoft. office. interOP. word. wdpagenumberalignment. wdalignpagenumbercenter; // center the page number. Note that the page number must be added before use. Otherwise, an exception occurs. <br/> oword. selection. headerfooter. pagenumbers [1]. alignment = Microsoft. office. interOP. word. wdpagenumberalignment. wdalignpagenumbercenter; <br/> oword. activewindow. view. seekview = Microsoft. office. interOP. word. wdseekview. wdseekmaindocument; // go to the body <br/>}< br/> Public void setsections () <br/>{< br/> // restore page number arrangement, otherwise, the following sections start again <br/> oword. activewindow. view. seekview = Microsoft. office. interOP. word. wdseekview. wdseekcurrentpagefooter; // go to the footer view <br/> oword. selection. headerfooter. pagenumbers. restartnumberingatsection = false; // reset the starting page number <br/> oword. activewindow. view. seekview = Microsoft. office. interOP. word. wdseekview. wdseekmaindocument; // go to the body <br/>}

 

Several interfaces or classes

1. headerfooter
Interface

Link toprevious to the previous section
A set of all page number (page number) fields in a header or footer of pagenumbers.

Range the text content of an object. This refers to the text content of the header or footer, which can be set or read.

2. pagenumbers
Interface

Restartnumberingatsection true if page numbering starts at 1 again at the beginning of the specified section.
Showfirstpagenumber true if the page number appears on the first page in the Section.
Startingnumber returns or sets the starting note number, line number, or page number.

 

FAQs:

1. How to make the first page in a section different from others?

How to enable word to automatically set and retrieve segment Header/footer information

Http://support.microsoft.com/kb/269565/zh-cn

Whether to make the header or footer of the first page different from other pagesSection
ObjectDifferentfirstpageheaderfooter
Attribute.

Odoc. Sections [3]. pagesetup. differentfirstpageheaderfooter =-1;
Odoc. Sections [3]. headers [word. wdheaderfooterindex. wdheaderfooterfirstpage]. range. Text = "header on the first page ";
Odoc. Sections [3]. headers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. Text = "headers on other pages ";
Odoc. Sections [3]. footers [word. wdheaderfooterindex. wdheaderfooterfirstpage]. range. Text = "footer on the first page ";
Odoc. Sections [3]. footers [word. wdheaderfooterindex. wdheaderfooterprimary]. range. Text = "footer of other pages ";

 

Differentfirstpageheaderfooter
What is the type of attribute value?

In msdn, the document says it isTrue
If a different header or footer is used on the first page. can beTrue
,False
, OrWdundefined.
However, in C # programming, true is used, but an error is returned. This is acceptable in VB. The following is an explanation:

Http://social.msdn.microsoft.com/Forums/zh-CN/worddev/thread/e9f963a9-18e4-459a-a588-17824bd3906d

The value is an int in C #, and the documentation is not as helpful as it cocould be.


For "true", you need to use-1


For "false", you need to use 0


I do not think you can/set/This value to wdundefined (I. e.
Word. wdconstants. wdundefined). However, word may/return/that value,
Whose integer value is 9999999) If you have more than one section
Different values of differentfirstpageheaderfooter,
And you test


Activedocument. pagesetup. differentfirstpageheaderfooter


Rather than the value for a participant section.


(2) How many pages of word computing statistics, such

 

Itotalpages = odoc. computestatistics (wdstatisticpages)
It seems that there is an odoc statistical attribute that can also directly obtain the statistical information without testing.
 

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.