Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Description

Excerpt

This class is a low level representation of a field. This encompasses many objects in Word, such as merge fields, hyperlinks, TOC entries, etc. Fields are the generic form of what are contained in a Element's inline elements.

Signature
C#
C#
 public class Field : Element
{signature}{signature:
}
Signature
vb.net
vb.net
Public Class Field
		Inherits Element
{signature}
{remarks}To create a field, call the corresponding 
Remarks

To create a field, call the corresponding "insert"

method

for

what

you

want

to

create

\

(hyperlink,

TOC

entry,

etc

\

)

on

an

[

Element

|Element]

or

[

Position

|Position]

object.

To

get

an

existing

field,

use

the

[

Element.GetElements()

|Element.GetElements(Element.Type)]

method

and

pass

in

the

[

Element.Type.Field

|Element.Type#Field]

parameter

to

retrieve

all

fields.

The

following

sample

demonstrates

creating

a

field

at

the

end

of

a

new

document

and

retrieving

the

first

field

of

an

existing

document.

{remarks} {example}{code:csharp|title=C#}

Example
Code Block
csharp
csharp
titleC#


          //--- Insert a field at the end of a new document
          WordApplication app = new WordApplication();
          Document doc = app.Create();
          Field fld =
               doc.InsertHyperlinkAfter("http://www.softartisans.com", "SoftArtisans");

          //--- Get the first field of an existing document
          WordApplication app = new WordApplication();
          Document doc = app.Open(@"C:\sample.doc");
          Field firstField = doc.GetElements(Element.Type.Field)[0];
        
{code} {code:
Code Block
vb.net
|title=
vb.net
titlevb.net
}


          '--- Insert a field at the end of a new document
          Dim app As New WordApplication()
          Dim doc As Document = app.Create()
          Dim fld As Field = _
               doc.InsertHyperlinkAfter("http://www.softartisans.com", "SoftArtisans")

          '--- Get the first field of an existing document
          Dim app As New WordApplication()
          Dim doc As Document = app.Open("C:\sample.doc")
          Dim firstField As Field = doc.GetElements(Element.Type.Field)(0)
        
{code} {example} {properties} ||Name||Description|| |[Code|Field.Code]|{excerpt-include:Field.Code|nopanel=true}| |[Contents|Field.Contents]|{excerpt-include:Field.Contents|nopanel=true}| |[Type|Field.Type]|{excerpt-include:Field.Type|nopanel=true}| {methods} ||Name||Description|| |[Update()|Field.Update()]|{excerpt-include:Field.Update()|nopanel=true}| {classes} ||Name||Description|| |[FieldType|Field.FieldType]|{excerpt-include:Field.FieldType|nopanel=true}|
Properties

Name

Description

Code

Excerpt Include
Field.Code
Field.Code
nopaneltrue

Contents

Excerpt Include
Field.Contents
Field.Contents
nopaneltrue

Type

Excerpt Include
Field.Type
Field.Type
nopaneltrue
Methods

Name

Description

Update()

Excerpt Include
Field.Update()
Field.Update()
nopaneltrue
Classes

Name

Description

FieldType

Excerpt Include
Field.FieldType
Field.FieldType
nopaneltrue