Author Topic: Ignored header and footer while automating document generation  (Read 9015 times)

blaisephilip

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
I'm using a self-developed document generator add-in in EA V16.1.1628 to create .docx files as output. The following code is the main part of exporting the EA content:

Code: [Select]
      Package package = currentRepository.GetTreeSelectedPackage();
      DocumentGenerator docGen = currentRepository.CreateDocumentGenerator();
      docGen.NewDocument(cfgHandling.reqSpecSecTemplateName);
      docGen.SetPageOrientation(DocumentPageOrientation.pagePortrait);
      docGen.InsertCoverPageDocument(cfgHandling.reqSpecSecCoverPageName);
      docGen.SetStyleSheetDocument(cfgHandling.reqSpecSecStyleSheetName);
      docGen.InsertBreak(DocumentBreak.breakPage);
      docGen.InsertTOCDocument(cfgHandling.reqSpecSecTOCName);
      docGen.InsertBreak(DocumentBreak.breakPage);
      // call the iterative content generation
      contentGenerator(docGen, cfgHandling.logwindowName, currentRepository, package, 0, cfgHandling.reqSpecSecTemplateName);

      string filepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + cfgHandling.mainSavePath + "\\" + cfgHandling.project_id + "_Req_Spec." + cfgHandling.mainDocExt;
      CleanUpGeneratedFile(filepath);
      docGen.SaveDocument(filepath, cfgHandling.mainDocType);

cfgHandling.reqSpecSecTemplateName refers to the name of the template in the repository that contains the desired formatting.  (note: I use a MySQL database behind Pro Cloud Server)

The following is the header I use in the document's template:


This is completely ignored in the output document. I get blank header and footer, so the result breaks the rules of corporate guidelines, and renders the output in this form not usable.
Could anyone suggest which part of the code or EA overrides the template's header formatting?
(As backup plan, I'm considering writing a post-processor with Microsoft.Office.Interop.Word if fixing the Sparx EA document build fails.)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 12978
  • Karma: +540/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Ignored header and footer while automating document generation
« Reply #1 on: April 09, 2024, 07:04:18 pm »
You might have an empty (containing a single space) header/footer in one of the other templates.

I had this problem a while ago. The only way (I know) to get rid of these empty headers/footers is to create a new template and copy the contents to the new template.

And make sure you never touch the header/footer option.

I now only set a header/footer in either the cover page, or the TOC template, and never in the templates with the actual content.

Geert

blaisephilip

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: Ignored header and footer while automating document generation
« Reply #2 on: April 10, 2024, 03:03:21 am »
Thanks for the hints, Geert.
After spending the day recreating templates and stylesheets, I decided that only a document post-processor independent from EA will do this right.
There is absolutely zero effect on the headers and footers in my case in the output documents, not even by using the built-in templates, if I use the EA.DocumentGenerator.
The manual process works good but that is not suitable for my needs if I need to repetitively generate lots of instances.