C # Get the page number of a paragraph in Word

Source: Internet
Author: User

Method one: Obtained from XML structure through OPENXML
cannot be done. The reasons are as follows
A footer is isn't on a page and a page number in a footer are a field that potentially identifies with multiple pages. In a Word document file, there is no pages. Pages is set as a part of the printing process.
It is possible with the file open in Word to identify a page number using Visual Basic but it's not part of the XML.
In translation, the footer does not exist on the page, and the page number on the footer is a field that can be determined by multiple pages. In a Word document, and there is no page, the page is considered a Word page drawing process.
Using VBA to open a document in Word determines the page number, but the page number does not exist on the XML.

In this case, you can get a portion of the page number from the XML structure. That is, the directory exists in Word. But you can only get the page where the outline title is. You cannot specify a paragraph arbitrarily. and is not guaranteed to be accurate, because the directory is not automatically updated by default.
Although the page number does not exist in the XML structure, the page that corresponds to the outline title on the directory is hardcoded in the XML structure.

Way two: Through VBA-because VBA needs to open Word, it is possible to get the page number

/// <summary>        ///get paragraph page number/// </summary>        /// <param name= "Pa" ></param>        /// <returns></returns>         Public Static intgetpagenumberofparagraph (Paragraph pa) {returnGetpagenumberofrange (Pa.        Range); }        Private Static intGetpagenumberofrange (range range) {return(int) range.get_information (Wdinformation.wdactiveendpagenumber); }

C # Get the page number of a paragraph 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.