Message-ID: <288240408.8679.1711655023140.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8678_1437209752.1711655023140" ------=_Part_8678_1437209752.1711655023140 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Fax Sheet Cover

Fax Sheet Cover

Intro

A fax cover sheet with rec= ipient and sender information, created by WordTemplate.


The template document is a formatted fax cover form with merge fi= elds for every string, bool or int in the code. 

Code

=20
  public class FaxCoverGenerator
    {
 
        private string toName, fromName,=
 company, faxNumber, phoneNumber, subject, comments;
        private int pageCount;
        private bool isUrgent, isForRevi=
ew, isCommentRequested;
 
        /// <summary>
        /// Build the report with WordTe=
mplate
        /// </summary>
        public void GenerateDocument()
        {
            //Desire=
d values for the cover sheet:
            this.toN=
ame =3D "Jon Smith";
            this.fro=
mName =3D "Robert Jones";
            this.com=
pany =3D "SoftArtisans";
            this.fax=
Number =3D "(123)-456-7890";
            this.pho=
neNumber =3D "(123)-555-5555";
            this.sub=
ject =3D "Sales Report";
            this.com=
ments =3D "Attached is the sales report.";
            this.isU=
rgent =3D true;
            this.isF=
orReview =3D true;
            this.isC=
ommentRequested =3D true;
            this.pag=
eCount =3D 10;
 
            // Form =
the array of mergefield names. 
            // The e=
lements in this array correspond
            // to th=
e names of the merge fields in the
            // templ=
ate, and each element's array index
            // shoul=
d correpond to an element in the value array
           
            string[]=
 arrNames =3D {"ToName", "FromName", "Company"=
;, "FaxNumber", "PhoneNumber",
            &nb=
sp;            =
           "Subject&=
quot;, "PageCount", "Comments", "ChkUrgent", =
"ChkReview", "ChkComment"};
 
            // The v=
alue array.  The value of the elements in this
            // array=
 contain info supplied in the web form.
            // These=
 values represent the data that will be dynamically
            // popul=
ated in the template file
           
            object[]=
 arrValues =3D {this.toName, this.fromName, this.company, this.faxNumber, t=
his.phoneNumber,
            &nb=
sp;            =
            this.sub=
ject, this.pageCount, this.comments,
            &nb=
sp;            =
            this.isU=
rgent?"X":"", this.isForReview?"X":"&quo=
t;, this.isCommentRequested?"X":""};
 
 
            // Creat=
e the WordTemplate object
            WordTemp=
late wt =3D new WordTemplate();
 
            // Open =
the template document.
            string t=
emplatePath =3D @"..\..\WordTemplateFiles\FaxCoverTemplate.docx";
            wt.Open(=
templatePath);
 
            // Set t=
he datasource with the name and value arrays defined above
            wt.SetDa=
taSource(arrValues, arrNames);
 
            // Proce=
ss the template
            wt.Proce=
ss();
 
            // Save =
the document
            wt.Save(=
@"..\..\WordOutputFiles\FaxCover_output.docx");
 
        }
 
=20

 Downloads

=20

Template:  FaxCoverTemplate.docx

Output:  FaxCover_output.docx

=20
------=_Part_8678_1437209752.1711655023140--