Message-ID: <336879282.7929.1711626601664.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_7928_1840081447.1711626601664" ------=_Part_7928_1840081447.1711626601664 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
DataBindProperties
object provides the means to change how dat=
a is imported using ExcelTemplate.
The DataBindingProperties= object controls how the data is bound when the BindData method is called. The= DataBindingProperties can control the maximum number of rows that are impo= rted, whether the data is transposed and which worksheet the data is import= ed to.
In this sample, we use two DataBindingProperties objects-topEmployeeProp= erties and allEmployeeProperties-to create two different worksheets: one co= ntaining only the 10 employees with the most sales and one containing = all the sales employees. By setting the MaxRows property to 10 w= ith the topEmployeeProperties object, we are able to display only= the top 10 sales people in the AdventureWorks database.
public void GenerateReport() { //Open t= he template file ExcelTem= plate xlt =3D new ExcelTemplate(); xlt.Open(@&qu= ot;..\..\ExcelTemplateFiles\BindingPropertiesTemplate.xlsx"); //Get th= e data to bind to the template DataTabl= e salesPeople =3D getSalesPeople(); DataTabl= e salesPeople2 =3D getSalesPeople(); //We wil= l bind the data in two places, using the same data source name. //In the= "Top 10" worksheet we will place the 10 sales people who have //earned= the most money from sales this year DataBind= ingProperties topEmployeesProperties =3D xlt.CreateDataBindingProperties(); topEmplo= yeesProperties.MaxRows =3D 10; topEmplo= yeesProperties.WorksheetName =3D "Top 10"; //In the= "Employees" worksheet, we will place all sales people DataBind= ingProperties allEmployeesProperties =3D xlt.CreateDataBindingProperties(); allEmplo= yeesProperties.WorksheetName =3D "Employees"; //Bind t= he data to the template. While the same data object cannot be bound //in two= different places, we can have data sources on two different worksheets //that h= ave the same name, so long as we specify which worksheet we want to bind //to in = the DataBindingProperties object. xlt.Bind= Data(salesPeople, "SalesPerson", topEmployeesProperties); xlt.Bind= Data(salesPeople2, "SalesPerson", allEmployeesProperties); //Proces= s the template, and save it. xlt.Proc= ess(); xlt.Save(@"..\..\ExcelOutputFiles\BindingProperties_output= .xlsx"); } private DataTable getSalesPeople= () { DataTable dt =3D new DataTable(); dt.Colum= ns.Add("FirstName", typeof(string)); dt.Colum= ns.Add("LastName", typeof(string)); dt.Colum= ns.Add("SalesYTD", typeof(double)); dt.Rows.= Add("Linda", "Mitchell", 5200475.231); dt.Rows.= Add("Jae", "Pak", 5015682.231); dt.Rows.= Add("Michael", "Blythe", 4557045.0459); dt.Rows.= Add("Jillian", "Carson", 3857163.6332); dt.Rows.= Add("Ranjit", "Varkey Chudukatil", 3827950.238); dt.Rows.= Add("David", "Campbell", 3587378.426); dt.Rows.= Add("Jose", "Saraiva", 3189356.247); dt.Rows.= Add("Shu", "Ito", 3018725.486); dt.Rows.= Add("Tsvi", "Reiter", 2811012.715); dt.Rows.= Add("Rachel", "Valdez", 2241204.042); dt.Rows.= Add("Tete", "Mensa-Annan", 1931620.184); dt.Rows.= Add("Garrett", "Vargas", 1764938.986); dt.Rows.= Add("Lynn", "Tsoflias", 1758385.926); dt.Rows.= Add("Stephen", "Jiang", 677558.4653); dt.Rows.= Add("Amy", "Alberts", 636440.251); dt.Rows.= Add("Syed", "Abbas", 219088.8836); dt.Rows.= Add("Pamela", "Ansman-Wolfe", 0); return d= t; } }=20