Message-ID: <165854796.10371.1711722719157.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_10370_563233996.1711722719157" ------=_Part_10370_563233996.1711722719157 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Using an Array as a Data Source

Using an Array as a Data Source

The following sample generates an Excel spreadsheet from a template= using arrays as data sources.

Code sample: Using an Array as the Data Source

[C#] [VB.NET]

The first data marker in the template is *%%=3D$SimpleArray*. *%%=3D$* indicates that the data source is either a= simple variable or a 1-dimensional array that is a data source for a singl= e column.

=20
=20

Data Marker Format for 1-D Arrays

=20 Icon=20
=20

For a single column data marker that will be bound to a 1-dimensional ar= ray data source by the method BindColumnData, use the data marker format *%%=3D$Data= MarkerName*. For a set of data markers with multiple fields that w= ill be bound to a 1-dimensional array data source by the method BindRowData, use the data marke= r format *%%=3DDataMarkerName.Field* (without a *$= *). For more information, see Creating Data Markers.

=20
=20
=20

In ArrayDataSource.aspx.cs, the BindColumnData method is called to set the data source fo= r *%%=3D$SimpleArray* to a one-dimensional array:

=20
string[] onedim =3D {"SoftArtisans", "OfficeWriter&qu=
ot;, "ExcelTemplate"};x
lt.BindColumnData(onedim, "SimpleArray",xlt.CreateDataBindingProp=
erties());
=20
=20
 Dim onedim As String() =3D {"SoftArtisans", "Of=
ficeWriter", "ExcelTemplate"}
xlt.BindColumnData(onedim, "SimpleArray", xlt.CreateDataBindingPr=
operties())
=20

ExcelTemplate.Bind= ColumnData sets a data source for a template column to a 1-dimensional = array of objects. The method's first parameter, onedim, is the data source = array. The second parameter, "SimpleArray", is the name of the te= mplate data marker to which the data source binds. The third parameter, xlt= .CreateDataBindingProperties(), is a DataBindingProperties object that contains values that change = how the data are bound to the template; in this case, the default property = values are used.

 

The method BindData = binds the data markers *%%=3DTwoDimArray.#1*, *%%= =3DTwoDimArray.#2*, and *%%=3DTwoDimArray.#3* to = a 2-dimensional string array:

=20
string[][] twodim =3D {
    new string[]{"Nancy", "Davolio", "Sales Manage=
r"},
    new string[]{"Michael", "Suyama", "HR Represen=
tative"},
    new string[]{"Adrian", "King", "IS Support&quo=
t;}
    };
string[] names =3D {"FirstName", "LastName", "Posi=
tion"};
xlt.BindData(twodim, names,"TwoDimArray", xlt.CreateDataBindingPr=
operties());
=20
=20
Dim twodim()() As String =3D New String()() { _
    New String(){"Nancy", "Davolio", "Sales Manage=
r"}, _
    New String(){"Michael", "Suyama", "HR Represen=
tative"}, _
    New String(){"Adrian", "King", "IS Support&quo=
t;} _
    }
Dim names As String() =3D {"FirstName", "LastName", &qu=
ot;Position"}
xlt.BindData(twodim,  names,  "TwoDimArray", xlt.CreateDataBindin=
gProperties())
=20

BindData's first parameter is the 2-dimensional array of strings to use = as the data source. The second parameter specifies an array of column names= .

The third parameter - "TwoDimArray" - is the name of the templ= ate data marker to which the data source binds. The fourth parameter - xlt.= CreateDataBindingProperties() - is a DataBindingProperties object that contains values that change = how the data are bound to the template; in this case, the default property = values are used.

There are three "TwoDimArray" data markers; their fields are s= pecified by ordinal (#1, #2, and #3). The columns of values in the data sou= rce bind to the data markers by order. That is, the first column of values = will populate *%%=3DTwoDimArray.#1*, the second will popul= ate *%%=3DTwoDimArray.#2*, and the third *%%=3DTwo= DimArray.#3*.

BindRowData sets = a data source for the row of data markers *%%=3DAddress.Street*, *%%=3DAddress.City*, and *%%=3DAddress.Stat= e* to a 1-dimensional array:

=20
string[] addressvalues =3D {"3 Brook St.", "Watertown=
", "MA"};
string[] addressnames =3D {"Street", "City", "Stat=
e"};
xlt.BindRowData(addressvalues,addressnames,"Address",xlt.CreateDa=
taBindingProperties());
=20
=20
Dim addressvalues As String() =3D {"3 Brook St.", "Wa=
tertown", "MA"}
Dim addressnames As String() =3D {"Street", "City", &qu=
ot;State"}
xlt.BindRowData(addressvalues, addressnames, "Address", xlt.Creat=
eDataBindingProperties())
=20

 

The first parameter of BindRowData, addressvalues, specifies the array o= f values to bind to the data markers. The second parameter, addressnames, i= s the array of data marker field names. The values in the data source array= will bind to the data marker fields by field name. The third parameter, &q= uot;Address", is the name of the data marker to which ExcelTemplate bi= nds the data. The fourth parameter, xlt.CreateDataBindingProperties(), is a= DataBindingProperties o= bject that contains values that change how the data are bound to the templa= te; in this case, the default property values are used.

Data Marker Code

%%=3D$SimpleArray

=20
 string[] onedim =3D {"SoftArtisans",
    "OfficeWriter",
    "ExcelTemplate"};
xlt.BindColumnData(onedim,
    "SimpleArray",
    xlt.CreateDataBindingProperties());
=20
=20
Dim onedim As String() =3D {"SoftArtisans", _
    "OfficeWriter", _
    "ExcelTemplate"}
xlt.BindColumnData(onedim, _
    "SimpleArray", _
    xlt.CreateDataBindingProperties()) 
=20

%%=3DTwoDimArray.#1

%%=3DTwoDimArray.#2

%%=3DTwoDimArray.#3


=20
string[][] twodim =3D {
    new string[]{"Nancy", "Davolio", "Sales Manage=
r"},
    new string[]{"Michael", "Suyama", "HR Represen=
tative"},
    new string[]{"Adrian",
        "King",
        "IS Support"}
    };
string[] names =3D {"FirstName", "LastName", "Posi=
tion"};
xlt.BindData(twodim,
    names,
    "TwoDimArray",
    xlt.CreateDataBindingProperties());
=20
=20
Dim twodim()() As String =3D New String()() { _
    New String(){"Nancy", "Davolio", "Sales Manage=
r"}, _
    New String(){"Michael", "Suyama", "HR Represen=
tative"}, _
    New String(){"Adrian", _
        "King", _
        "IS Support"}
    }
Dim names As String() =3D {"FirstName", "LastName", &qu=
ot;Position"}
xlt.BindData(twodim, _
    names, _
    "TwoDimArray", _
    xlt.CreateDataBindingProperties())
=20

%%=3DAddress.Street

=20
string[] addressvalues =3D {"3 Brook St.",
    "Watertown",
    "MA"};
string[] addressnames =3D {"Street", "City", "Stat=
e"};
xlt.BindRowData(addressvalues,
    addressnames,
    "Address",
    xlt.CreateDataBindingProperties());
=20
=20
Dim addressvalues As String() =3D {"3 Brook St.", _
    "Watertown", _
    "MA"}
Dim addressnames As String() =3D {"Street", "City", &qu=
ot;State"}
xlt.BindRowData(addressvalues, _
    addressnames, _
    "Address", _
    xlt.CreateDataBindingProperties()
=20

 

 

------=_Part_10370_563233996.1711722719157--