Message-ID: <1850525620.8749.1711658872856.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8748_239045930.1711658872856" ------=_Part_8748_239045930.1711658872856 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Sample Expense Report

Sample Expense Report

Intro

This sample uses Exc= elTemplate to populate a generic expense report template.

This example demonstrates how to use single object data markers (ones th= at start with %%=3D$) to import the data for the header by calling the Bind= CellData method multiple times.  It also demonstrates how to use 2-D a= rray data markers to import expense data from an Object array by calling th= e BindData method once.

=20
= =20

Requirements

=20
This sample requires OfficeWriter Enterprise Edition to be installed becau= se the OfficeWriter Grouping and Nesting is only available in the Enterpris= e Edition of the product.=20
=20
=20

Code

=20
public class ExpenseReport 
    {
        /// <summary>
        /// Build the report with ExcelTemplate
        /// </summary>
        public void GenerateReport()
        {
            // Here we create some data to po=
pulate into 
            //the template for the sample In =
your application 
            //this data could possibly come s=
traight from a database
            

            // These strings will bind to var=
iable data markers 
            string empPurpose =3D "Quart=
erly Expense Report";
            string empName =3D "Sammy Mc=
Dougal";
            string empDept =3D "Sales (E=
astern region)";
            string empSSN =3D "111-222-1=
212";
            string empPosition =3D "VP&q=
uot;;
            string empID =3D "242";
            string empManager =3D "C.M. =
Burns";
            string dateFrom =3D "1/1/200=
2";
            string dateTo =3D "5/31/2002=
";

            // These arrays hold data that bi=
nd to the array 
            //data markers and will be repeat=
ed
            //in the template for each row im=
ported
            
            string[] colNames =3D { "Dat=
e", "Description", "Hotel", "Fuel", &quo=
t;Meals", "Misc" };

            object[,] values =3D {{"1/2/=
2002", "2/5/2002", "3/15/2002", "4/10/2002&qu=
ot;, "5/17/2002"}, 
                     =
;           {"Dev Conference", "Lun=
ch w/ Client", "Delivery", "Dinner w/ Client", &qu=
ot;Sales Seminar"}, 
                     =
;           {200.04, 223.43, 184.23, 331.24, 112.1=
1}, 
                     =
;           {10.00, 0.99, 11.23, 32.23, 10.00},&nb=
sp;
                     =
;           {30.00, 23.04, 44.44, 19.99, 5.00},&nb=
sp;
                     =
;           {5.00, 11.00, 13.03, 3.24, 33.12}};

            // Create an instance of ExcelTem=
plate 
            ExcelTemplate xlt =3D new ExcelTe=
mplate();

            // Open the template workbook&nbs=
p;
            xlt.Open(@"..\..\ExcelTempla=
teFiles\ExpenseReportTemplate.xlsx");

            // Pass the strings to the BindCe=
llData method    
            DataBindingProperties cellBinding=
Properties =3D xlt.CreateDataBindingProperties();
            xlt.BindCellData(empPurpose, &quo=
t;EmpPurpose", cellBindingProperties);
            xlt.BindCellData(empName, "E=
mpName", cellBindingProperties);
            xlt.BindCellData(empDept, "E=
mpDept", cellBindingProperties);
            xlt.BindCellData(empSSN, "Em=
pSSN", cellBindingProperties);
            xlt.BindCellData(empPosition, &qu=
ot;EmpPosition", cellBindingProperties);
            xlt.BindCellData(empID, "Emp=
ID", cellBindingProperties);
            xlt.BindCellData(empManager, &quo=
t;EmpManager", cellBindingProperties);
            xlt.BindCellData(dateFrom, "=
DateFrom", cellBindingProperties);
            xlt.BindCellData(dateTo, "Da=
teTo", cellBindingProperties);

            // Limit the number of rows to th=
e maximum number of rows that Excel
             //can support. ExcelTemplat=
e expects the array's first index to be
             //the row number and the se=
cond index to be the column number. Our
             //array is the opposite, so=
 we have to transpose the data.
             
            DataBindingProperties bindingProp=
erties =3D xlt.CreateDataBindingProperties();
            bindingProperties.MaxRows =3D Exc=
elTemplate.ALL_ROWS;
            bindingProperties.Transpose =3D t=
rue;
            xlt.BindData(values, colNames, &q=
uot;Exp", bindingProperties);


            // Call the Process() method to p=
opulate the template 
            //with the data source values
            
            xlt.Process();

            // Save the report
            xlt.Save(@"..\..\ExcelOutput=
Files\ExpenseReport_output.xlsx");
        }
        
    }



=20



=  

Downloads

------=_Part_8748_239045930.1711658872856--