Word

Adapter

public class Adapter : IDisposable

The Word adapter lets you modify the content of a Word document.

 Methods

bool SetDocumentBytes(byte[] data)

Load document as binary data

MemoryStream GetDocumentStream()

Read document in binary data from memory

bool ReplaceBookmark(string bookmarkName, string bookmarkText)

Insert the specified text at the place of the given bookmark. (Replace placeholder text, if existing)

bool ReplaceBookmarkKeepFormat(string bookmarkName, string bookmarkText)

Insert the specified text at the place of the given bookmark while keeping the existing format

bool ReplaceBookmark2(string name, string text, string formats)

Insert the specified text at the place of the given bookmark. You may work with multiline text (e.g. the addressee)

bool ReplaceBookmarkAsHyperlink(string name, string text, string url)

Insert the specified text as a hyperlink at the place of the given bookmark

bool FillBookmarkTable(string name, DataRows datarows, bool keepfirstrow = true)

Insert the specified data table at the place of the given bookmark

void Dispose()

Releases the resources used

DataRows

public class DataRows : List<DataRow>

DataRow

public class DataRow : List<DataColumn>

 Properties

DataFormat Format

Row format

DataColumn

public class DataColumn

 Properties

string Content

Content of the column

DataColumnAlignment Align

Alignment of the column content

DataFormat Format

Format of the column content

DataFormat

public enum DataFormat

 Enum

None

0
Normal content

Bold

1
Content in bold

Italic

2
Content in italics

UnderlineSingle

4
Content with a single underline

UnderlineDouble

8
Content with a double underline

DataColumnAlignment

public enum DataColumnAlignment

 Enum

Left

0
Content is left-justified

Right

1
Content is right-justified

Center

2
Content is centered

Decimal

3
Content is aligned with the decimal point

Example

This example modifies the content of a Word document. The variable myfile points to a file which may either be uploaded from a web form or which could be retrieved out of a data store.

import clr
clr.AddReferenceToFileAndPath(Session.GetAdapterPath("IYOPRO.WORD"))
from IYOPRO.WORD import *

data = ProcessInstance.ReadFileBytes(myfile)
with Adapter() as word:
   word.SetDocumentBytes(data)
   word.ReplaceBookmark('MyBookMark','Hello World')
   stream = word.GetDocumentStream()
   ProcessInstance.WriteFileFromMemoryStream(myfile,stream)