Office Programming is essential and office programming is essential

Source: Internet
Author: User

Office Programming is essential.

1. Official Microsoft instance:

Paragraphs, tables, and charts

How to: Use Visual C #. net to automatically create a document in Word

 

2. Learning Resources

(1) Basic knowledge of Word in the Office, which must be read. the following summary contains a summary.

Http://msdn.microsoft.com/en-us/library/Aa201330

Http://blog.csdn.net/hustliangchen/archive/2011/01/05/6118459.aspx:

(2) Structure of the Word class, including Application, document, Range, and Selection, which must be read

Http://msdn.microsoft.com/en-us/library/aa164012

(3) word 2007 object model:

Http://msdn.microsoft.com/en-us/library/bb244515 (v = office.12). aspx

(4) Microsoft. Office. Interop. Word

Http://msdn.microsoft.com/zh-cn/library/ms254954 (v = Office.11). aspx

(5) WPS secondary development interface documentation wpsapi. chm

Easy to read Chinese and download CSDN

(6) moth Word VBA reference tutorial

All Chinese word class libraries, must read

Http://www.feiesoft.com/vba/word/

(7) using VBA Macros to improve Word operation efficiency-20 classic instances that require excellent research

Http://pcmag.hexun.com/2010-03-18/123031946.html

 

3. Summary

(1) Document represents a specific word Document. Documents are a collection of Documents and are represented by an index. The ActiveDocument attribute is the document of the current focus. We generally do not use indexes to reference documents, because the index value changes as the document is opened or closed. Usually we use the ActiveDocument attribute, or the document object variable returned by the Add or Open method of the Documents set is referenced. Add or Open document will become ActiveDocument. To make other documents activeDocument, use the ActiveDocument method of the document Object.

Specify the specific ingress net with the file name,Documents("Report.doc").Activate();

 

(2) characters form words, words form sentences, and sentences form paragraphs. Therefore, a document contains four collections: Characters Words, Sentences, and Paragraphs collection. In addition, the document may contain a set of sections, and a section contains a set of HeadersFooters headers and footers.

 

(3) A Paragraph consists of a Paragraph sign and all texts. When a paragraph is copied, if the paragraph logo is included, the paragraph format is also copied. If you do not want to copy the paragraph logo, do not copy the paragraph logo.

 

(3) The Range object represents a continuous area defined by the START character and end character. It can be as small as one insert cursor or as large as the entire document content, it can also be but not necessarily the region represented by the current selection. Multiple Range objects can be defined in a document.

We usually use the Range class to define a variable to create a Range object, and then use the Range method of Document or the Range attribute of other objects to instantiate this Range object.

 

(4) Selection object

Can represent the cursor

This object represents the currently selected content in the window or pane. The selected content indicates the selected (or highlighted) area in the document. If no selected content exists in the document, it indicates the insertion point. Each document pane can have only one active Selection object and only one active Selection object in the application.
Use Selection object
You can use the Selection attribute to return the Selection object. If no object identifier is used for the Selection attribute, Word returns the selected content from the activity pane in the activity document window.

The Text attribute is the selected content.

Copy, Cut, and Paste operations

 

(5) sections

Sections. Add Method

This method is used to return a Section object, which indicates the new Section added to the document.
Function Add ([Range As Range = 0], [Start As WpsSectionStart = 2]) As Section

Parameter description
Range Variant type. Optional. The area before which the Delimiter is inserted. If this parameter is ignored, the Delimiter is inserted at the end of the document.
Start Variant type. Optional. The delimiter type to add. WpsSectionStart type. If this parameter is ignored, a "next page" type is added.
The WpsSectionStart type can be one of the following constants:
Value description
WpsSectionContinuous continuous delimiter
WpsSectionEvenPage even number of page Splitters
End of wpsSectionNewColumn
WpsSectionNewPage next page delimiter (default)
WpsSectionOddPage

Sections refer to MSDN

Section refer to MSDN

 

4. Specific Use

(1) how to set the title style, refer to "Title 1" and "title 2"

[C-sharp]View plaincopyprint?

/// Add a common section // public void AddParagraph (string s) {Word. paragraph p; p = oDoc. content. paragraphs. add (ref missing); p. range. text = s; object style = Word. wdBuiltinStyle. wdStyleBodyText; p. set_Style (ref style); p. range. insertParagraphAfter ();}

 

(2) how to insert a table

Using the Table class of Word, some people also use the DataTable class for assistance

 

(3) how to insert Images

InlineShapes is an Embedded Graph resource in Word.

[C-sharp]View plaincopyprint?

 

? Why does the image disappear after it is inserted?

This may be because you have inserted an image, but you have not moved the cursor, so the image is overwritten.

Solution: move the cursor

 

(4) move the cursor

A: Tag:

System pre-defined Tag: object oEndOfDoc = "// endofdoc ";

Custom Tag:

B: use tags to obtain the location

Word. Range wrdRng = oDoc. Bookmarks. get_Item (ref oEndOfDoc). Range;

This position is used when inserting paragraphs and tables:

OPara3 = oDoc. Content. Paragraphs. Add (ref oRng );

OTable = oDoc. Tables. Add (wrdRng, 3, 5, ref oMissing, ref oMissing );

[C-sharp]View plaincopyprint?

 

(5) generate a directory

[C-sharp]View plaincopyprint?

 

(6) how to set the directory format? For example, bold or skewed

Use paragraph format settings

[C-sharp]View plaincopyprint?

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.