FieldDde class

FieldDde class

Implements the DDE field. To learn more, visit the Working with Fields documentation article.

Remarks

For information copied from another application, this field links that information to its original source file using DDE.

Inheritance: FieldDdeField

Constructors

NameDescription
FieldDde()The default constructor.

Properties

NameDescription
auto_updateGets or sets whether to update this field automatically.
display_resultGets the text that represents the displayed field result.
(Inherited from Field)
endGets the node that represents the field end.
(Inherited from Field)
formatGets a FieldFormat object that provides typed access to field’s formatting.
(Inherited from Field)
insert_as_bitmapGets or sets whether to insert the linked object as a bitmap.
insert_as_htmlGets or sets whether to insert the linked object as HTML format text.
insert_as_pictureGets or sets whether to insert the linked object as a picture.
insert_as_rtfGets or sets whether to insert the linked object in rich-text format (RTF).
insert_as_textGets or sets whether to insert the linked object in text-only format.
insert_as_unicodeGets or sets whether to insert the linked object as Unicode text.
is_dirtyGets or sets whether the current result of the field is no longer correct (stale) due to other modifications made to the document.
(Inherited from Field)
is_linkedGets or sets whether to reduce the file size by not storing graphics data with the document.
is_lockedGets or sets whether the field is locked (should not recalculate its result).
(Inherited from Field)
locale_idGets or sets the LCID of the field.
(Inherited from Field)
prog_idGets or sets the application type of the link information.
resultGets or sets text that is between the field separator and field end.
(Inherited from Field)
separatorGets the node that represents the field separator. Can be None.
(Inherited from Field)
source_full_nameGets or sets the name and location of the source file.
source_itemGets or sets the portion of the source file that’s being linked.
startGets the node that represents the start of the field.
(Inherited from Field)
typeGets the Microsoft Word field type.
(Inherited from Field)

Methods

NameDescription
get_field_code()Returns text between field start and field separator (or field end if there is no separator). Both field code and field result of child fields are included.
(Inherited from Field)
get_field_code(include_child_field_codes)Returns text between field start and field separator (or field end if there is no separator).
(Inherited from Field)
remove()Removes the field from the document. Returns a node right after the field. If the field’s end is the last child of its parent node, returns its parent paragraph. If the field is already removed, returns None.
(Inherited from Field)
unlink()Performs the field unlink.
(Inherited from Field)
update()Performs the field update. Throws if the field is being updated already.
(Inherited from Field)
update(ignore_merge_format)Performs a field update. Throws if the field is being updated already.
(Inherited from Field)

Examples

Shows how to use various field types to link to other documents in the local file system, and display their contents.

def field_linked_objects_as_text():
    for insert_linked_object_as in (InsertLinkedObjectAs.TEXT, InsertLinkedObjectAs.UNICODE, InsertLinkedObjectAs.HTML, InsertLinkedObjectAs.RTF):
        with self.subTest(insert_linked_object_as=insert_linked_object_as):
            doc = aw.Document()
            builder = aw.DocumentBuilder(doc)
            # Below are three types of fields we can use to display contents from a linked document in the form of text.
            # 1 -  A LINK field:
            builder.writeln('FieldLink:\n')
            insert_field_link(builder, insert_linked_object_as, 'Word.document.8', MY_DIR + 'Document.docx', None, True)
            # 2 -  A DDE field:
            builder.writeln('FieldDde:\n')
            insert_field_fde(builder, insert_linked_object_as, 'Excel.Sheet', MY_DIR + 'Spreadsheet.xlsx', 'Sheet1!R1C1', True, True)
            # 3 -  A DDEAUTO field:
            builder.writeln('FieldDdeAuto:\n')
            insert_field_fde_auto(builder, insert_linked_object_as, 'Excel.Sheet', MY_DIR + 'Spreadsheet.xlsx', 'Sheet1!R1C1', True)
            doc.update_fields()
            doc.save(ARTIFACTS_DIR + 'Field.field_linked_objects_as_text.docx')

def field_linked_objects_as_image():
    for insert_linked_object_as in (InsertLinkedObjectAs.PICTURE, InsertLinkedObjectAs.BITMAP):
        with self.subTest(insert_linked_object_as=insert_linked_object_as):
            doc = aw.Document()
            builder = aw.DocumentBuilder(doc)
            # Below are three types of fields we can use to display contents from a linked document in the form of an image.
            # 1 -  A LINK field:
            builder.writeln('FieldLink:\n')
            insert_field_link(builder, insert_linked_object_as, 'Excel.Sheet', MY_DIR + 'MySpreadsheet.xlsx', 'Sheet1!R2C2', True)
            # 2 -  A DDE field:
            builder.writeln('FieldDde:\n')
            insert_field_fde(builder, insert_linked_object_as, 'Excel.Sheet', MY_DIR + 'Spreadsheet.xlsx', 'Sheet1!R1C1', True, True)
            # 3 -  A DDEAUTO field:
            builder.writeln('FieldDdeAuto:\n')
            insert_field_fde_auto(builder, insert_linked_object_as, 'Excel.Sheet', MY_DIR + 'Spreadsheet.xlsx', 'Sheet1!R1C1', True)
            doc.update_fields()
            doc.save(ARTIFACTS_DIR + 'Field.field_linked_objects_as_image.docx')

def insert_field_link(builder: aw.DocumentBuilder, insert_linked_object_as: 'ExField.InsertLinkedObjectAs', prog_id: str, source_full_name: str, source_item: str, should_auto_update: bool):
    """ExField.InsertLinkedObjectAs.BITMAP"""
    field = builder.insert_field(aw.fields.FieldType.FIELD_LINK, True).as_field_link()
    if insert_linked_object_as == ExField.InsertLinkedObjectAs.TEXT:
        field.insert_as_text = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.UNICODE:
        field.insert_as_unicode = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.HTML:
        field.insert_as_html = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.RTF:
        field.insert_as_rtf = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.PICTURE:
        field.insert_as_picture = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.BITMAP:
        field.insert_as_bitmap = True
    field.auto_update = should_auto_update
    field.prog_id = prog_id
    field.source_full_name = source_full_name
    field.source_item = source_item
    builder.writeln('\n')

def insert_field_fde(builder: aw.DocumentBuilder, insert_linked_object_as: 'ExField.InsertLinkedObjectAs', prog_id: str, source_full_name: str, source_item: str, is_linked: bool, should_auto_update: bool):
    """Use a document builder to insert a DDE field, and set its properties according to parameters."""
    field = builder.insert_field(aw.fields.FieldType.FIELD_DDE, True).as_field_dde()
    if insert_linked_object_as == ExField.InsertLinkedObjectAs.TEXT:
        field.insert_as_text = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.UNICODE:
        field.insert_as_unicode = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.HTML:
        field.insert_as_html = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.RTF:
        field.insert_as_rtf = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.PICTURE:
        field.insert_as_picture = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.BITMAP:
        field.insert_as_bitmap = True
    field.auto_update = should_auto_update
    field.prog_id = prog_id
    field.source_full_name = source_full_name
    field.source_item = source_item
    field.is_linked = is_linked
    builder.writeln('\n')

def insert_field_fde_auto(builder: aw.DocumentBuilder, insert_linked_object_as: 'ExField.InsertLinkedObjectAs', prog_id: str, source_full_name: str, source_item: str, is_linked: bool):
    """Use a document builder to insert a DDEAUTO, field and set its properties according to parameters."""
    field = builder.insert_field(aw.fields.FieldType.FIELD_DDEAUTO, True).as_field_dde_auto()
    if insert_linked_object_as == ExField.InsertLinkedObjectAs.TEXT:
        field.insert_as_text = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.UNICODE:
        field.insert_as_unicode = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.HTML:
        field.insert_as_html = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.RTF:
        field.insert_as_rtf = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.PICTURE:
        field.insert_as_picture = True
    elif insert_linked_object_as == ExField.InsertLinkedObjectAs.BITMAP:
        field.insert_as_bitmap = True
    field.prog_id = prog_id
    field.source_full_name = source_full_name
    field.source_item = source_item
    field.is_linked = is_linked

class InsertLinkedObjectAs(Enum):
    # LinkedObjectAsText
    TEXT = 1
    UNICODE = 2
    HTML = 3
    RTF = 4
    # LinkedObjectAsImage
    PICTURE = 5
    BITMAP = 6

See Also