User`s guide
13 Create a Report Program
13-88
2
Append the AutoNumber to a Text, Paragraph, or Heading object that contains the
text that precedes the automatic number.
append(chapHead,chapterNumber);
3
Append an mlreportgen.dom.CounterInc format object to the Style property of
the content object that you want to automatically number. Appending a CounterInc
object increments the stream associated with the automatic number when the
paragraph or heading is output. The updated value replaces the AutoNumber object.
chapHead.Style = {CounterInc('chapter'), WhiteSpace('preserve')};
This script automatically numbers the chapter headings in a document.
import mlreportgen.dom.*;
d = Document('MyReport','html');
for rank = 3:5
chapHead = Heading(1,'Chapter ','Heading 1');
append(chapHead,AutoNumber('chapter'));
append(chapHead,sprintf('. Rank %i Magic Square',rank));
chapHead.Style = {CounterInc('chapter'), ...
WhiteSpace('preserve')};
append(d,chapHead);
table = append(d,magic(rank));
table.Width = '2in';
end
close(d);
rptview(d.OutputPath);
Create Hierarchical Automatic Numbering
You can create hierarchical numbering schemes, such as 1.1, 1.2, 1.3, 2.1, 2.2, and so
on. Use an mlreportgen.dom.CounterReset format object to reset a child automatic
number to its initial value when its parent number changes. For example, this script
uses a CounterReset format object to reset the chapter table number stream at the
beginning of each chapter.
import mlreportgen.dom.*;
d = Document('MyReport','html');
for rank = 3:2:9
chapHead = Heading(1,'Chapter ');
append(chapHead, AutoNumber('chapter'));