Hi Julian
i try to make some improvement to my mail-merge procedure to create a unique RTF document as a result of a sequence of mail-merge using WpReporter.
I have a TWPRichText who is the source for TWPSuperMerge (will call it WPTemplate) another TWPRichText who is the result of the merge (will call it WPMerge) and the last TWPRichText will contain the final document (will call it WPAllMerge).
The mail-merge will process a sequence of "Templates" one-by-one and will create the final document appending any single document as a separate section. I need to preserve header, footer, page settings and page margins of the appended document.
The problem is: for some sections this process seem to work but for some other sections the page margins (left/right) are not the same as the source document.
This is who i do
1) clear WPTemplate, WPMerge and WPAllMerge
2) load one template into WPTemplate
3) assign header and parStyle from WPTemplate to WPMerge
WPMerge->Clear();WPMerge->Header = WPTemplate->Header; // Assign page propertiesWPMerge->ParStyles()->Assign(WPTemplate->ParStyles());SuperMerge->SetSourceDest(WPTemplate->Memo->RTFData, WPMerge->Memo->RTFData);
3) run SuperMerge->Execute() to create merged document into WPMerge
4) append WPMerge to WPAllMerge as a new section (preserving header and footer, page settings and page margins of WPMerge) using this procedure:
void __fastcall TMailMergeEngine::AppendAsSection(TWPRichText * WPSource, TWPRichText * WPDest, bool headerAsSource){ TWPRTFSectionProps * sectionprops; TWPRTFDataBlock * textblock ; int i; // Create a new Page if required if (WPDest->IsEmpty()) WPDest->CheckHasBody(); else { WPDest->CPPosition = MaxInt; WPDest->InputString("\f",0); } // Create a new section sectionprops = WPDest->ActiveParagraph->StartNewSection(); // Assign the default page size if (WPSource == WPMerge) sectionprops->Assign(WPSource->Header); //sectionprops->Select = [wpsec_PageSize,wpsec_Margins]; sectionprops->Select << wpsec_PageSize << wpsec_Margins << wpsec_SelectHeaderFooter; // Copy all header + footer into certain section for (i=0; i < WPSource->HeaderFooter->Count; i++ ) { TWPRTFDataBlock * src = WPSource->HeaderFooter->Items[i]; if ( src->Kind == wpHeader || src->Kind == wpFooter ) { textblock = WPDest->HeaderFooter->Append(WPSource->HeaderFooter->Items[i]->Kind, WPSource->HeaderFooter->Items[i]->Range, WPSource->HeaderFooter->Items[i]->Name ); textblock->UsedForSectionID = sectionprops->SectionID; textblock->RtfText->Assign(WPSource->HeaderFooter->Items[i]->RtfText); } } // The current paragraph starts this section WPDest->ActiveParagraph->SectionID = sectionprops->SectionID; // Go to end of file WPDest->CPPosition = MaxInt; //i need to insert a space before coping the text otherwise i cannot see section start simbol on editor WPDest->InputString(' ', 0); // Copy the text as part of a certain section WPDest->SelectionAsString = WPSource->AsANSIString("RTF");}
5) repeat the sequence from step 2 for all documents who i need to process
6) Assign all WPAllMerge contents to WPMerge with this procedure
void __fastcall TMailMergeEngine::CopyWPText(TWPRichText * WPSource, TWPRichText * WPDest){ WPDest->Clear(); WPDest->AsString = WPSource->AsANSIString("RTF");}
7) save WPMerge on a RTF file
8) open the RTF on a TWPRichText to show or edit it
I tried also to append sections using this code as in your example but the result are worst:
TWPRTFSectionProps * sectionprops = WpEngine->WPAllMerge->HeaderFooter->AppendAsSection(WpEngine->WPMerge->HeaderFooter)
sectionprops->Select = sectionprops->Select << wpsec_SelectHeaderFooter
Where is the error?
Best regards,
Enrico Raviglione.
RadStudio 2010 C++Builder personality
WpTools v 6.16