Add Content as a Group

You can use a group to include the same content in different parts of a report. The DOM API clones the members of a group before appending them to another object.

This example shows the key code to include. After describing the steps involved in using a group, this example includes code for a complete report that uses a group.

  1. Define the DOM objects that you want to include repeatedly in a report.

    disclaimerHead = Heading(2,'Results May Vary');
    disclaimerIntro = Paragraph('The following results assume:');
    disclaimerList = UnorderedList(...
        {'Temperature between 30 and 70 degrees F',...
        'Wind less than 20 MPH','Dry road conditions'});
  2. Define a Group object that includes the DOM objects for the group. For example:

    disclaimer = Group();
    append(disclaimer,disclaimerHead);
    append(disclaimer,disclaimerIntro);
    append(disclaimer,disclaimerList);
  3. Append the Group object in the place in the report where you want to repeat the content. For example, if the document object is doc:

    append(doc,disclaimer);

This code builds a report based on this approach.

import mlreportgen.dom.*;
doc = Document('groupReport','html');
disclaimerHead = Heading(2,'Results May Vary');
disclaimerIntro = Paragraph('The following results assume:');
disclaimerList = UnorderedList(...
    {'Temperature between 30 and 70 degrees F',...
    'Wind less than 20 MPH','Dry road conditions'});
disclaimer = Group();
append(disclaimer,disclaimerHead);
append(disclaimer,disclaimerIntro);
append(disclaimer,disclaimerList);
append(doc,disclaimer);
p1 = Paragraph('First set of results...');
p1.Bold = true;
p2 = Paragraph('more report content...');
p2.Bold = true;
append(doc,p1);
append(doc,p2);
append(doc,disclaimer);
close(doc);
rptview('groupReport','html');

See Also

Functions

Classes

Related Topics