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