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
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)