C # obtain the number of pages of a Word document and go to the specified page to obtain page information

Source: Internet
Author: User

Using MSWord = Microsoft. Office. InterOP. word;

 

Private MSWord. Application wordapp; // word ApplicationProgramVariable
Private MSWord. Document worddoc; // Word document variable
Private object nothing = missing. value;
// Initialization
Wordapp = new MSWord. applicationclass ();
Worddoc = wordapp. Documents. Add (ref nothing, ref nothing );
// Open Word
Object filename = strpath;
Object readonly = false;
Object isvisible = true;
Worddoc = wordapp. Documents. Open (ref filename, ref nothing, ref readonly,
Ref nothing, ref nothing,
Ref nothing, ref isvisible, ref nothing,
Ref nothing, ref nothing, ref nothing );

 

// Calculate the number of pages in a Word document
MSWord. wdstatistic stat = MSWord. wdstatistic. wdstatisticpages;
Int num = worddoc. computestatistics (stat, ref nothing );

// Jump to the specified bookmarks
Object bookmarkname = "bookmark1 ";
Object what = MSWord. wdgotoitem. wdgotobookmark;
Worddoc. activewindow. selection. Goto (ref what, ref nothing, ref nothing, ref bookmarkname );
MessageBox. Show (worddoc. activewindow. selection. Paragraphs [1]. range. Text. tostring ());

// Jump to the specified page

Object what = MSWord. wdgotoitem. wdgotopage;
Object which = MSWord. wdgotodirection. wdgotonext;
Object Name = "1"; // Number of pages
Worddoc. activewindow. selection. Goto (ref what, ref which, ref nothing, ref name); // The second parameter can use nothing
Worddoc. activewindow. selection. Paragraphs [1]. range. Text. tostring ();

// The following operations are performed after a page is jumped.

// You can use pagesetup to obtain information about a page.

// Retrieve the column of the page
Worddoc. activewindow. selection. pagesetup. textcolumn;

Related Article

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.