C # Some basic ways to manipulate word (Word print, insert file, insert Picture, Position header footer, remove horizontal line)

Source: Internet
Author: User

Microsoft.Office.Interop.Word.Application WordApp = new ApplicationClass ()

Word Object

2, Microsoft.Office.Interop.Word.Document WordDoc = WORDAPP.DOCUMENTS.ADD (ref nothing, ref no, ref nothing, ref Noth ing) Document Object

3, Object nothing = System.Reflection.Missing.Value a common parameter

4, WordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.

wdSeekCurrentPageHeader positioning to Header

5, WordApp.Selection.ParagraphFormat. Borders[wdbordertype.wdborderbottom]

. LineStyle = Wdlinestyle.wdlinestylenone Remove header line

6, WordApp.ActiveWindow.View.SeekView = Wdseekview.wdseekmaindocument jump out of the header

7, wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.

wdAlignParagraphCenter Alignment (this is centered)

8, Microsoft.Office.Interop.Word.Table policytab = WordDoc.Tables.Add

(WordApp.Selection.Range, number of rows, columns, ref nothing, ref nothing); Create a table

9, WordApp.Selection.GoTo (ref ogotoitem, ref ogotolast, ref nothing, ref anything); Locate the page (this is the end of the cursor positioned to the content)

10, WordApp.Selection.InsertBreak (ref nothing); Insert Section break

11, WordApp.Selection.InsertFile (Nofile, ref nothing, ref contenfalse, ref contenfalse, ref contenfalse); Insert File

12, WordApp.Selection.InlineShapes.AddPicture (Picname, ref linktofile, ref savewithdocument, ref nothing); Insert Picture

13, WordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.

wdSeekCurrentPageFooter; Navigate to Footer

14, WordApp.Selection.TypeText ("Write the text you need to output at the specified location"); text input

15, Worddoc.computestatistics (Wdstatistic.wdstatisticpages, ref nothing); Get page number

16, Worddoc.printout (ref nothing, ref no, ref nothing, ref nothing,

Ref nothing, ref nothing, ref nothing, ref nothing,

Ref nothing, ref nothing, ref nothing, ref nothing,

Ref nothing, ref nothing, ref nothing,

Ref nothing, ref no, ref nothing);

Call printer implementation to print (call default printer)

17, Worddoc.close (ref saveChanges, ref nothing, ref nothing); Document exit

18, Wordapp.quit (ref nothing, ref nothing, ref nothing); Word program exits

C # Some basic ways to manipulate word (Word print, insert file, insert Picture, Position header footer, remove horizontal line)

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.