We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

MailMerge - Repeat Header Row along with table row

I'm using DOC/IO to generate a report in WPF. I have a table with a Header Row and a row beneath it. Each row represents a data record in the database.

Is there a way to to have the header row repeat for each instance of the data record?

Below is the code for the mail merge, and attached is an image showing the Current Format that reflects the code below, and the New Format that I wish to display.

------------ code begins here --------------------------
public WtBpSolution( string Name, string ObjectName, string ReportBitMapFullPathName, DateTime StartDate, DateTime EndDate, Patient CurrentPatient, PDUser CurrentUser, object ParamObject )
{
try
{
this.Name                     = Name;
this.StartDate                = StartDate;
this.EndDate                  = EndDate;
this.CurrentPatient           = CurrentPatient;
this.ObjectName               = ObjectName;
this.CurrentUser              = CurrentUser;
this.ReportBitMapFullPathName = ReportBitMapFullPathName;
}
catch( Exception )
{
throw;
}
}

/// <summary>
/// 
/// </summary>
/// <param name="AbsoluteFullPathTemplateLocation"></param>
/// <returns></returns>
public override PdfDocument RunReportPDFOutFromWordTemplate( string AbsoluteFullPathTemplateLocation )
{
try
{
bool GetCycleData = true;

string PatientWeightKgs = null;
string PatientWeightLbs = null;
string BodyTemperatureCelsius = null;
string BodyTemperatureFahrenheit = null;

double BloodGL_MMOLL = 0.0;
double BloodGL_MGDL = 0.0;

List<WtBpSolutionData> DataList = new List<WtBpSolutionData>();
ObservableCollection<Treatment> Treatments = Treatment.PatientForDateRange( this.CurrentPatient.PatientIDInternal, this.StartDate, this.EndDate, GetCycleData );
if( Treatments != null && Treatments.Count > 0 )
{
foreach( Treatment t in Treatments )
{
if( t.PatientWeight < 0 )
{
PatientWeightKgs = Math.Round( ( t.PatientWeight - ApplicationConstant.SI_UNIT_OFFSET ) / 10.0, 2 ).ToString();
PatientWeightLbs = Math.Round( ( t.PatientWeight * ApplicationConstant.KG_TO_LB ) / 10.0, 2 ).ToString();
}
else
{
PatientWeightKgs = Math.Round( t.PatientWeight * ApplicationConstant.LB_TO_KG, 2).ToString();
PatientWeightLbs = t.PatientWeight.ToString();
}

if( t.Therapy >= 5 )
{
PatientWeightKgs = Math.Round( PatientWeightKgs.ToDouble() / 10.0, 2 ).ToString();
PatientWeightLbs = Math.Round( PatientWeightLbs.ToDouble() / 10.0, 2 ).ToString();

if( t.BodyTemp < 0 )
{
BodyTemperatureFahrenheit = Math.Round( Utils.C_TO_F( ( t.BodyTemp - ApplicationConstant.SI_UNIT_OFFSET ) / 10.0 ), 1 ).ToString();
BodyTemperatureCelsius = Math.Round( t.BodyTemp / 10.0, 1 ).ToString();
}
else
{
BodyTemperatureFahrenheit = Math.Round( t.BodyTemp / 10.0, 1 ).ToString();
BodyTemperatureCelsius = Math.Round( Utils.F_TO_C( ( t.BodyTemp / 10.0 ) ), 1 ).ToString();
}

if( t.BloodGl < 0 )
{
BloodGL_MMOLL = Math.Round( ( ( t.BloodGl - ApplicationConstant.SI_UNIT_OFFSET ) * ApplicationConstant.MMOLL_TO_MGDL ) / 10.0, 1 );
BloodGL_MGDL = Math.Round(t.BloodGl / 10.0, 1 );
}
else
{
BloodGL_MMOLL = Math.Round(t.BloodGl / 10.0, 1 );
BloodGL_MGDL = Math.Round( ( t.BloodGl * ApplicationConstant.MGDL_TO_MMOLL ) / 10.0, 1 );
}
}
else
{
BodyTemperatureCelsius = t.BodyTemp.ToString();
BodyTemperatureFahrenheit = t.BodyTemp.ToString();

BloodGL_MMOLL = t.BloodGl;
BloodGL_MGDL = t.BloodGl;
}

DataList.Add( new WtBpSolutionData
{
ReportLogo        = this.ReportBitMapFullPathName,
PatientName       = this.CurrentPatient.Name,
Age               = this.GetAge( this.CurrentPatient.DOB ).ToString(),
ReportName        = this.Name,
PatientIDExternal = this.CurrentPatient.PatientIDExternal,
PhysicianName     = this.CurrentPatient.PhysicianName,
UserName          = this.CurrentUser.Name,
ReportDate        = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(),

TestDate                  = t.TreatmentDate.ToShortDateString(),
StartTime                 = t.FirstDrainStart.ToString(),
BloodPressureSystolic     = t.BPSystolic.ToString(),
BloodPressureDiastolic    = t.BPDiastolic.ToString(),
PatientWeightKgs          = PatientWeightKgs,
PatientWeightLbs          = PatientWeightLbs,
SolutionTypes_1           = "Dextrose 1.5%,  \t " + t.SolBagSize1.ToString() + " ml",
SolutionTypes_2           = "Dextrose 2.5%,  \t " + t.SolBagSize2.ToString() + " ml",
SolutionTypes_4           = "Dextrose 4.25%, " + t.SolBagSize3.ToString() + " ml",
LastSolutionTypeName      = Treatment.GetSolutionTypeString( t.LastSolType ),
BloodGL_MMOLL             = BloodGL_MMOLL.ToString(),
BloodGL_MGDL              = BloodGL_MGDL.ToString(),
Pulse                     = t.Pulse.ToString(),
BodyTemperatureCelsius    = BodyTemperatureCelsius,
BodyTemperatureFahrenheit = BodyTemperatureFahrenheit
} );
}
}
else
{
DataList.Add( new WtBpSolutionData
{
ReportLogo        = this.ReportBitMapFullPathName,
PatientName       = this.CurrentPatient.Name,
Age               = this.GetAge( this.CurrentPatient.DOB ).ToString(),
ReportName        = this.Name,
PatientIDExternal = this.CurrentPatient.PatientIDExternal,
PhysicianName     = this.CurrentPatient.PhysicianName,
UserName          = this.CurrentUser.Name,
ReportDate        = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(),
} );
}

//
// Get a mail merge data table object
//
MailMergeDataTable mailmergeDataTable = new MailMergeDataTable( this.ObjectName, DataList );

//
// Create the word document, open it, turn off clear fields and merge the table
//
WordDocument document = new WordDocument();
document.Open( AbsoluteFullPathTemplateLocation, FormatType.Docx );
document.MailMerge.MergeField += new MergeFieldEventHandler( AlternateRows_MergeField );
document.MailMerge.MergeImageField += new MergeImageFieldEventHandler( MergeField_ProductImage );
document.MailMerge.ClearFields = false;
document.MailMerge.ExecuteGroup( mailmergeDataTable );

//
// Turn on clear fields, grab the first row of the DataList and put it into a list and pass merge non row word fields on it
//
document.MailMerge.ClearFields = true;
List<WtBpSolutionData> dl = new List<WtBpSolutionData>();
dl.Add( DataList[ 0 ] );
document.MailMerge.Execute( dl );

//
// Convert to PDF document and return
//
PdfDocument pdfDoc = new DocToPDFConverter().ConvertToPDF( document );
return pdfDoc;
}
catch( Exception )
{
throw;
}
}
}
--------- code ends here, see attached for visuals -----------------------


mailmerge_6b4efb17.zip

1 Reply

SS Siva Subramanian Syncfusion Team March 25, 2013 01:14 PM UTC

Hi Carol, 

Thank you for using Syncfusion products. 

We have prepared the sample to illustrate your requirement to repeat the header row for each instance of the mail merge data record. Please do find the sample from the attachment. Try running the sample and let us know if this meets your requirement. 

If the given sample doesn’t meets your requirement , please provide us the sample along with the input template document which you have used to generate the word document on your side, so that we can further analyze and update you with the appropriate details. 

Please let us know if you have questions. 

Regards,

Sivasubramanian.



GenerateWord_WPF_27d9b672.zip

Loader.
Live Chat Icon For mobile
Up arrow icon