Using MSWord = Microsoft. Office. InterOP. word;
MSWord. Application wordapp; // word application variable
MSWord. Document worddoc; // Word document variable
Object nothing = missing. value; // Initialization
Wordapp = new MSWord. applicationclass ();
Worddoc = wordapp. Documents. Add (ref nothing, ref nothing, refnothing, ref nothing); // create a word
// Open an existing word
Object filename = strpath;
Object readonly = false;
Object isvisible = true;
Worddoc = wordapp. documents. open (ref filename, ref nothing, refreadonly, ref nothing, ref isvisible, ref nothing, ref nothing, refnothing,
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 what = MSWord. wdgotoitem. wdgotobookmark;
Object bookmarkname = "bookmark1 ";
Worddoc. activewindow. selection. Goto (ref what, ref nothing, refnothing, 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, refnothing, ref name); // The second parameter can use nothing
MessageBox. Show (worddoc. activewindow. selection. Paragraphs [1]. range. Text. tostring ());
MessageBox. Show (worddoc. activewindow. selection. Sentences [1]. Text. tostring ());
MessageBox. Show (worddoc. activewindow. selection. Paragraphs [1]. range. Sentences [1]. Text. tostring ());
MessageBox. Show (worddoc. content. Paragraphs [8]. range. Text. tostring ());
MessageBox. Show (worddoc. content. Paragraphs [8]. range. Sentences [1]. Text. tostring ());
// Insert paragraph and pagination
Word. Paragraph opara4;
Opara4 = mydoc. content. Paragraphs. Add (ref omissing );
Opara4.range. Text = "Figure 1 :";
Opara4.range. Font. Name = "";
Opara4.range. Font. size = 10.5f;
Opara4.range. insertparagraphafter ();
Insertchart (savedocpath); // insert an Excel-Chart
Opara4.range. insertparagraphafter ();
// Insert a paging character
Insertbreaknextpage ();
// Use a regular expression to segment a paragraph
String string2 = "section 1. \ R \ n section 2. \ R \ n section 3. ";
String [] paras = system. Text. regularexpressions. RegEx. Split (string2, @ "\ r \ n ");
// Insert a carriage return.
Word. selection. typeparagraph ();
// Insert a return character
Word. selection. typebackspace ();
// Jump to the end of the document
Object wd_story = word. wdunits. wdstory;
Word. selection. endkey (ref wd_story, ref omissing );