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

...

Use

...

a

...

repeat

...

block

...

to

...

import

...

multiple

...

rows

...

from

...

a

...

data

...

source.

...

A

...

repeat

...

block

...

is

...

a

...

fragment

...

in

...

the

...

template

...

document

...

-

...

defined

...

by

...

a

...

Word

...

bookmark

...

-

...

that

...

contains

...

merge

...

fields

...

and

...

that

...

will

...

be

...

repeated

...

for

...

each

...

row

...

in

...

a

...

data

...

source.

...

To

...

import

...

multiple

...

rows

...

from

...

a

...

single

...

data

...

source,

...

create

...

a

...

repeat

...

block

...

in

...

the

...

template

...

and,

...

in

...

the

...

WordWriter

...

code,

...

call

...

SetRepeatBlock

...

to

...

bind

...

the

...

repeat

...

block

...

to

...

a

...

data

...

source.

...


The

...

main

...

document

...

is

...

any

...

part

...

of

...

the

...

template

...

that

...

is

...

not

...

within

...

a

...

repeat

...

block.

...

SetDataSource

...

sets

...

a

...

single-row

...

data

...

source

...

for

...

merge

...

fields

...

in

...

the

...

main

...

document.

...

If

...

you

...

pass

...

SetDataSource

...

a

...

ResultSet

...

that

...

contains

...

more

...

than

...

one

...

row,

...

WordWriter

...

will

...

import

...

the

...

first

...

row

...

to

...

the

...

template.

...

Multiple

...

row

...

data

...

sources

...

can

...

be

...

imported

...

to

...

repeat

...

blocks

...

only,

...

not

...

to

...

main

...

document

...

merge

...

fields.

...

To

...

create

...

a

...

repeat

...

block:

...

  1. In

...

  1. Microsoft

...

  1. Word,

...

  1. create

...

  1. a

...

  1. text

...

  1. fragment,

...

  1. a

...

  1. list,

...

  1. or

...

  1. a

...

  1. table

...

  1. row

...

  1. that

...

  1. contains

...

  1. merge

...

  1. fields

...

  1. .
  2. Select the text,

...

  1. list,

...

  1. or

...

  1. table

...

  1. row

...

  1. that

...

  1. you

...

  1. want

...

  1. to

...

  1. define

...

  1. as

...

  1. a

...

  1. repeat

...

  1. block.

...

  1. Open

...

  1. the

...

  1. Insert

...

  1. menu

...

  1. and

...

  1. select

...

  1. Bookmark...

...

  1. to

...

  1. open

...

  1. the

...

  1. Bookmark

...

  1. dialog.

...

  1. Enter

...

  1. a

...

  1. bookmark

...

  1. name

...

  1. and

...

  1. click

...

  1. Add

...

  1. .

...

In

...

Microsoft

...

Word,

...

bookmarks

...

are

...

not

...

marked

...

by

...

default.

...

To

...

see

...

which

...

document

...

fragments

...

are

...

bookmarks:

...

  1. Open

...

  1. the

...

  1. Tools

...

  1. menu

...

  1. and

...

  1. select

...

  1. Options...

...

  1. Select

...

  1. the

...

  1. View

...

  1. tab.

...

  1. Under

...

  1. Show

...

  1. ,

...

  1. check

...

  1. Bookmarks

...

  1. .

...

  1. Bookmarks

...

  1. will

...

  1. be

...

  1. marked

...

  1. by

...

  1. grey

...

  1. brackets.

...

Whether

...

the

...

template

...

will

...

bind

...

to

...

one

...

data

...

source

...

or

...

several,

...

merge

...

fields

...

are

...

not

...

required

...

in

...

the

...

main

...

document.

...

To

...

import

...

multiple

...

rows

...

from

...

a

...

single

...

data

...

source,

...

use

...

a

...

repeat

...

block

...

only,

...

and

...

do

...

not

...

include

...

any

...

merge

...

fields

...

in

...

the

...

main

...

document.

...

The

...

repeat

...

block

...

can

...

span

...

all

...

the

...

content

...

in

...

the

...

document.

...

For

...

example,

...

by

...

defining

...

a

...

repeat

...

block

...

with

...

a

...

bookmark

...

that

...

spans

...

an

...

entire

...

page,

...

and

...

setting

...

a

...

multiple-row

...

data

...

source,

...

you

...

can

...

use

...

WordWriter

...

to

...

create

...

multiple

...

form

...

letters:

...

Image Added

Here is some example code that demonstrates the usage of SetRepeatBlock with a DataTable that has multiple rows. This code inserts data into merge fields "FirstName" and "LastName" enclosed in the repeat block named "BookMarkName".

Csharp
void GenerateDocument(int employeeID)
{
     //--- Query the database
     DataTable dt = new DataTable();
     using(SqlConnection conn = new SqlConnection(connString))
     {
          string sql =
               "SELECT FirstName, LastName FROM Employee";
          SqlDataAdapter adpt = new SqlDataAdapter(sql, conn);
          adpt.Fill(dt);
     }

     //--- Use a DataTable as the data source
     WordTemplate wt = new WordTemplate();
     wt.Open(templatePath);
     wt.SetRepeatBlock(dt, "BookMarkName");
     wt.Process();
     wt.Save(Page.Response, "RepeatBlockOutput.doc", false);
}
{csharp}
{vbnet}
Private Sub 
Vbnet

Private Sub GenerateDocument(ByVal

employeeID

As

Integer)


'---

Query

the

database Dim dt As New

database
Dim dt As New DataTable()

Dim conn As New


Dim conn As New SqlConnection(connString)

Dim sql As String = _ "SELECT FirstName, LastName FROM Employee"" Try Dim adpt As New


Dim sql As String = _
"SELECT FirstName, LastName FROM Employee""
Try
Dim adpt As New SqlDataAdapter(sql,

conn)


adpt.Fill(dt)

Finally If Not conn Is Nothing Then


Finally
If Not conn Is Nothing Then
conn.Dispose()

End If End Try


End If
End Try

'---

Use

a

DataTable

as

the

data

source Dim wt As New

source
Dim wt As New WordTemplate()


wt.Open(templatePath)


wt.SetRepeatBlock(dt,

"BookMarkName")


wt.Process()


wt.Save(Page.Response,

"RepeatBlockOutput.doc",

False)


End

Sub {vbnet} h2. Code

Sub

Code Sample:

...

Mail

...

Merge

...

using

...

Repeat

...

Blocks

...

The

...

following

...

code

...

sample

...

demonstrates

...

the

...

use

...

of

...

SetRepeatBlock

...

to

...

emulate

...

mail

...

merge

...

behavior.

...

The

...

repeat

...

block

...

spans

...

an

...

entire

...

page

...

within

...

the

...

document.

...

This

...

causes

...

a

...

new

...

page

...

to

...

be

...

created

...

for

...

each

...

recipient

...

in

...

the

...

database:

...

[

...

C# |

...

VB.NET

...

]

...