Message-ID: <1431743124.9017.1711672420741.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_9016_936534741.1711672420741" ------=_Part_9016_936534741.1711672420741 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
This demo illustrates some of the formulas available for WordTemplate in= OfficeWriter 4.1 and above.
With OfficeWriter 4.1 and above, WordTemplate provides a selection of fo= rmulas that enhance Word's built-in formulas. A WordTemplate formula = is specified as a mergefield and has a special syntax:«=3DSUM= (datasource.fieldname)». A WordTemplate formula operates on = a column of values in the data source and can be placed anywhere in a docum= ent. In OfficeWriter 4.1 and above, the following WordTemplate formul= as are available:
=20=09public void GenerateDocument() { WordTemp= late wt =3D new WordTemplate(); // Creat= e the array of mergefield names string[]= fields =3D new string[] { "TestDate", "School", "= Town", "Version" }; // Creat= e the array of values, each of which corresponds to a mergefield above object[]= values =3D new object[] { new Date= Time(2009, 11, 16).ToShortDateString(),"Samuel Adams HS", "M= ilbury", wt.Version}; // Open = the template document wt.Open(= @"..\..\WordTemplateFiles\TestScoreReportTemplate.docx"); // Set t= he main document data source wt.SetDa= taSource(values, fields, ""); // Retri= eve test score data DataTabl= e dt =3D GetScores(); // In a = repeat block, a new entry is inserted for each row in the // data = source. When the data source is a DataTable, the mergefield // names= are the same as the column names; so there is no need to // speci= fy mergefield names as we did above. However, we do have to set //a book= mark, "Items", so that wordwriter knows where to repeatedly bind = the data. wt.SetRe= peatBlock(dt, "Items"); // Popul= ate the template wt.Proce= ss(); // Save = the document to the disc in the desired location wt.Save(= @"..\..\WordOutputFiles\ScoreReport_output.docx"); } =09private DataTable GetScores() { DataTable dt =3D new DataTable(); dt.Columns.Add("StudentID&qu= ot;, typeof(string)); dt.Columns.Add("ReadingScore= ", typeof(int)); dt.Columns.Add("WritingScore= ", typeof(int)); dt.Columns.Add("MathScore&qu= ot;, typeof(int)); dt.Columns.Add("TotalScore&q= uot;, typeof(int)); Random rand =3D new Random(); int rScore, wScore, mScore; for (int i =3D 0; i < 30; ++i) { rScore =3D rand.Nex= t(400, 800); wScore =3D rand.Nex= t(400, 800); mScore =3D rand.Nex= t(400, 800); dt.Rows.Add( strin= g.Format("S{0:000000}", rand.NextDouble() * 1000000), rScor= e, wScore, mScore, rScore + wScore + mScore ); } DataTable dtSorted =3D dt.Clone()= ; foreach (DataRow row in dt.Select= ("", "StudentID asc")) dtSorted.ImportRow(= row); return dtSorted; }=20
Template: TestScoreReportTemplate.docx
=20Output: ScoreReport_output.docx
=20