Message-ID: <1404325522.9913.1711706595120.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9912_1213162020.1711706595120" ------=_Part_9912_1213162020.1711706595120 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html WordTemplate.SetRepeatBlock(System.Data.IDataReader, String, Int= 32)

WordTemplate.SetRepeatBlock(System.Data.IDataReader, String, Int32)=

Description

=20

Sets the specified repeat block's data source to an IDataReader interfac= e, which may be either a SqlDataReader, OleDbDataReader, or an AdomdDataRea= der.

=20
C#
=20
 public void SetRepeatBlock(System.Data.IDataReader dr, System.String bookm=
ark, int maxRows)
=20
=20
vb.net
=20
Public Sub SetRepeatBlock(ByVal dr As System.Data.IDataReader, ByVal bookma=
rk As String, ByVal maxRows As Integer)
=20
=20

Parameters

=20
dr
a SqlDataReader, OleDbDataReader or and AdomdDataReader to use= as the data source.=20
bookmark
=20

The bookmark name of the template repeat block. The bookmark passed to <= code>SetRepeatBlock must exist in the template Word file. To see a l= ist of template bookmark names:

=20
    =20
  1. Open the template in Microsoft Word.
  2. =20
  3. Open the Edit menu.
  4. =20
  5. Select Go To...
  6. =20
  7. Select Bookmark.
  8. =20
  9. Under Enter bookmark name, open the drop-down list of = bookmark names.
  10. =20
=20
maxRows
Specifies the maximum number of repetitions to write= to the file. If Next fields are enabled (see=20 Ena= bleNEXTFields), then the number of rows imported from the data source i= s=20 maxRows*(numberOfNextFields+1). If Next fields are not enabled= the number of rows imported is equal to the number of repetitions written = out. To write the maximum rows available, use the constant=20 WordTemplat= e.ALL_ROWS.=20

Exceptions

=20
ArgumentNullException
=20 SetRepeatBlock will throw this exception if=20 null (C#) or=20 Nothing (VB.NET) is passed to the method.=20
ArgumentException
=20

Introduced in build 8.4<= /h4>=20

SAException
=20 SetRepeatBlock will throw this exception if the=20 bookmark has been set to be=20 re= moved.=20

Remarks

=20

A repeat block is a fragment in the template document that will be repea= ted for each row in a data source. In the template document, repeat blocks = are defined by Word bookmarks that contain merge fields.

=20

You can call SetRepeatBlock several times for a single instance of WordTemplate. The repe= at block specified by the parameter bookmark must exist in the= template.

=20

If you pass an empty DataReader to SetRepeatBlock - by eith= er setting maxRows to 0 or passing an empty DataReader - WordW= riter will not include the specified repeat block in the generated Word fil= e.

=20

Not all Word features can be included in a repeat block:

$body=20
=20 =20 =20 =20 =20 =20 =20 =20 =20

Supported in Repeat Blocks

Not Supported in Repeat Blocks

    =20
  • Character Formatting (everywhere)
  • =20
  • Paragraph Formatting (Alignment, Outlines, Indent, Spacing, Page Break = before, Keep Together)
  • =20
  • Multiple Columns (2, 3, Column Breaks)
  • =20
  • Borders and Shading
  • =20
  • Tabs
  • =20
  • Bullets
  • =20
  • Numbering (numbering not reset, it is continued from one repeat block t= o another)
  • =20
  • Page Breaks
  • =20
  • Section Breaks
  • =20
  • Auto Text Field
  • =20
  • Hyperlink
  • =20
  • Pictures
  • =20
  • Table Row Repeat (entire row only)
  • =20
  • Fields (with some restrictions)
  • =20
    =20
  • Nested repeat blocks (Only one data source may be assigned to a single = repeat block.)
  • =20
  • Overlapping bookmarks
  • =20
  • Comments
  • =20
  • Drawing Objects
  • =20
  • Text Boxes
  • =20
  • Footnote and endnote references
  • =20
  • Table and picture indexes
  • =20
  • Single cell in a table
  • =20
  • Smart tags (smart tags will be removed from the document)
  • =20
  • Repeat blocks in headers, footers, footnotes, comments, text boxes, etc= .
  • =20
$body=20

Examples

=20
C#
=20

          //--- Get a DataReader
          //--- WordWriter accepts OleDbDataReader, SqlDataReader, and Adom=
dDataReader
          OleDbDataReader dr =3D GetOleDbDataReader();
          WordTempalte oWW =3D new WordTemplate();
          oWW.Open(Page.MapPath("./template.doc"));

          //--- Set a data source for the repeat block
          //--- defined by the bookmark "Page"
          //--- "dr" is the DataReader containing information to =
be
          //--- imported and repeated in the repeat block
          //--- Set MaxRows to 10.  Only 10 rows from the DataReader
          //--- will be imported
          oWW.SetRepeatBlock(dr, "Page", 10);
          oWW.Process();
          oWW.Save(Page.Response, "EmployeeOutput.doc", false);

          //--- Close the DataReader in a finally block
          dr.Close();
=20
          private OleDbDataReader GetOleDbDataReader()
          {
               OleDbConnection Conn =3D new OleDbConnection(connString);

               //--- SQL Query for categories.
               string CategorySQL =3D "SELECT CategoryID, CategoryName=
," +
                    "Description FROM Categories";
               Conn.Open();
               return new OleDbCommand(CategorySQL, Conn).ExecuteReader(
                    CommandBehavior.CloseConnection);
          }
        
=20
=20
vb.net
=20

          '--- Get a DataReader
          '--- WordWriter accepts OleDbDataReader, SqlDataReader, and Adomd=
DataReader
          Dim dr As OleDbDataReader =3D GetOleDbDataReader()
          Dim oWW As New WordTemplate()
          oWW.Open(Page.MapPath("./template.doc"))

          '--- Set a data source for the repeat block
          '--- defined by the bookmark "Page"
          '--- "dr" is the DataReader containing information to b=
e
          '--- imported and repeated in the repeat block
          '--- Set MaxRows to 10.  Only 10 rows from the DataReader
          '--- will be imported
          oWW.SetRepeatBlock(dr, "Page", 10)
          oWW.Process()
          oWW.Save(Page.Response, "EmployeeOutput.doc", False)

          '--- Close the DataReader in a finally block
          dr.Close()

          Private Function GetOleDbDataReader() As OleDbDataReader
               Dim Conn As New OleDbConnection(connString)

               '--- SQL Query for categories.
               Dim CategorySQL As String =3D "SELECT CategoryID, Categ=
oryName," & _
                    "Description FROM Categories"
               Conn.Open()
               Return New OleDbCommand(CategorySQL, Conn).ExecuteReader( _
                    CommandBehavior.CloseConnection)
          End Function
        
=20
------=_Part_9912_1213162020.1711706595120--