Main Content

Create Report API Base Tables

To generate tables that have titles, create the tables by using mlreportgen.report.BaseTable objects. You can also divide a table created as a BaseTable object into legible slices by using the properties of the object. You can use the BaseTable object only in Report API-based reports.

If the value of the Title property of the BaseTable object consists of inline content, the table titles are numbered. The numbering scheme depends on whether the BaseTable object is added to a report or a chapter. The numbering scheme in a chapter depends on whether the chapter is numbered or unnumbered. For more information, see the Title property of the mlreportgen.dom.BaseTable class.

For information about other types of tables that you can create in reports, see Choose Type of Table to Create.

Generate Tables with Numbered Titles

This example shows how to generate tables that have numbered titles. The example generates a report that has two tables with titles.

Import the Report API and the DOM API packages so that you do not have to use long, fully qualified class names.

import mlreportgen.dom.*
import mlreportgen.report.*

Create a Report API report.

rpt = Report('myTitledReport','pdf');

Create mlreportgen.report.BaseTable reporters from magic squares and specify the titles.

bt1 = BaseTable(magic(3));
bt1.Title = 'Magic Square with Order 3';
bt2 = BaseTable(magic(4));
bt2.Title = 'Magic Square with Order 4';

Add the BaseTable objects to the report. Close and view the report.

add(rpt,bt1);
add(rpt,bt2);
close(rpt);
rptview(rpt);

Format BaseTable Tables

By default, a BaseTable object generates a table with a grid style and a bold title. To customize the table, you can use the same approaches that you use with other types of tables. You can:

  • Format the DOM objects or DOM table objects before you use them to create the BaseTable object.

  • Create the title as a DOM object. Format the DOM object before you assign it to the Title property of the BaseTable reporter.

  • Set the TableStyleName of the BaseTable reporter to a custom style. The style must be defined in the template of the report to which the reporter is added or in the template of a reporter added to the report.

  • Format the table content after table creation. Access the content from the Content property of the BaseTable table.

See Format Tables.

Format an mlreportgen.dom.BaseTable Table and Title

This example shows how to format a DOM table before you create an mlreportgen.dom.BaseTable reporter from the table. The example also shows how to format the title of a BaseTable table. The example generates a table with a light blue background and a title that is not bold.

Set up the report.

import mlreportgen.dom.*
import mlreportgen.report.*
rpt = Report('myCustomBaseTable','pdf');

Create a DOM table. For example, create an informal table by using an mlreportgen.dom.Table object.

t = Table(magic(3));

Format the DOM table. For example, make the background color of the table light blue.

t.TableEntriesStyle = {BackgroundColor('lightsteelblue')};

Create a BaseTable reporter from the Table object.

bt = BaseTable(t);

Create an mlreportgen.dom.Text object for the title and format it. This example makes the weight of the title text regular instead of bold.

tabletitle = Text('Magic Square with Order 3');
tabletitle.Bold = false;

Set the Title property of the BaseTable object.

bt.Title = tabletitle;

Add the BaseTable object to the report.

add(rpt,bt);

close(rpt);
rptview(rpt);

Fit Wide BaseTable Tables in a Report

If a BaseTable table is too wide to be legible when scaled to fit a page, you can divide the table into legible slices by setting the MaxCols property to the maximum number of columns to display per slice.

You can control the style of the title of the table slice by using the TableSliceTitleStyleName property.

See Also

Related Topics