Main Content

mlreportgen.report.BaseTable Class

Namespace: mlreportgen.report
Superclasses: mlreportgen.report.Reporter

Create table reporter

Description

Use an object of the mlreportgen.report.BaseTable class to create a reporter for a table that has a title.

The mlreportgen.report.BaseTable class is a handle class.

Class Attributes

HandleCompatible
true

Creation

Description

table = mlreportgen.report.BaseTable creates an empty table reporter. Use the reporter properties to specify the table content, title, style, and width.

example

table = mlreportgen.report.BaseTable(content) creates a table reporter and sets the Content property to content.

table = mlreportgen.report.BaseTable(Name=Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Properties

expand all

Table title, specified as one of these values:

  • String scalar or character vector

  • DOM object

  • 1-by-N or N-by-1 array of strings or DOM objects

  • 1-by-N or N-by-1 cell array of strings, character vectors, or DOM objects

  • Hole reporter returned by the getTitleReporter method

If the title value is inline content, which is content included in a paragraph, the table reporter uses a template stored in its template library to format the title. The template automatically numbers the table title using a format that depends on whether the table is in a numbered or unnumbered chapter.

  • A table in a numbered chapter has a title text prefix of the form "Table N.M" where N is the chapter number and M is the table number in the chapter. For example, the prefix for the third table in the second chapter of the report is Table 2.3.

  • A table in unnumbered chapter has a title text prefix of the form "Table N" where N is 1 for the first table in the report, 2 for the second table, and so on.

In many non-English locales, the title prefix is translated to the language and format of the locale. See the Locale property of mlreportgen.report.Report for a list of translated locales.

Attributes:

GetAccess
public
SetAccess
public

Table content, specified as one of these values:

  • mlreportgen.dom.Table object

  • mlreportgen.dom.FormalTable object

  • mlreportgen.dom.MATLABTable object

  • Two-dimensional array or cell array of DOM or built-in MATLAB® objects

  • Hole reporter returned by getContentReporter method

Use the BaseTable constructor or add method to set this property. You cannot set it directly.

Attributes:

GetAccess
public
SetAccess
public

Name of the style to apply to the table, specified as a character vector or string scalar. The specified style must be a table style defined in the template used by the report to which you append this table or in the template of a reporter added to the report.

If TableStyleName is empty, the table style is the default table style defined by the template of the reporter, which is a grid.

Attributes:

GetAccess
public
SetAccess
public

Width of this table, specified as a character vector or string scalar that consists of a number followed by an abbreviation of a unit of measurement. Valid abbreviations are:

  • "px" — pixels

  • "cm" — centimeters

  • "in" — inches

  • "mm" — millimeters

  • "pc" — picas

  • "pt" — points

Attributes:

GetAccess
public
SetAccess
public

Maximum number of columns to display per table slice, specified as Inf or as a positive integer. If the value of this property is Inf, all original table columns are included in a single table. A MaxCols value greater than or equal to the number of table columns also produces a single table with all columns. Large table data sets may be illegible. Set this property to the number of columns from the original table that fit legibly on a page. To determine an optimal value, iterate setting the MaxCols value and viewing the report.

Attributes:

GetAccess
public
SetAccess
public

Number of initial columns to repeat per slice, specified as 0 or a positive integer. A nonzero number, n, repeats the first n columns of the original table in each slice. The MaxCols property value includes the RepeatCols property value. For example, if MaxCols is 6 and RepeatCols is 2, each table slice has a total of six columns with the first two columns repeated from the original table.

Attributes:

GetAccess
public
SetAccess
public

Name of the custom style to apply to the titles of table slices, specified as a string or a character vector. The specified style must be defined in the report to which this reporter is added. If this property is empty ('', "", or []), the slice titles use the default style defined in the reporter template.

Attributes:

GetAccess
public
SetAccess
public

Source of the template for this reporter, specified in one of these ways:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template is used for this reporter or whose template library contains the template for this reporter

  • DOM document or document part whose template is used for this reporter or whose template library contains the template for this reporter

The specified template must be the same type as the report to which you append this report. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Name of the template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template specified by the TemplateSrc property of this reporter.

Data Types: string | char

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID, or an mlreportgen.dom.LinkTarget object. A character vector or string scalar value converts to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Update table entries callback, specified as a function handle. The callback function accepts an mlreportgen.dom.TableEntry object as the input argument. Appending the BaseTable object to a report triggers the callback function once for each table entry before the table is appended to the report. Use this function to customize the appearance of table entries based on the content of the entries. For example, see Customize Table Entries by Content in a PDF Report.

Attributes:

GetAccess
public
SetAccess
public

Methods

expand all

Examples

collapse all

Add two tables that have titles to a report. The first table is a rank 5 magic square. The second table includes two images.

Run the following command to access the supporting files used in this example.

openExample('rptgen/MatlabReportGeneratorSupportFilesExample');
import mlreportgen.report.*
import mlreportgen.dom.*

rpt = Report("tables");
chapter = Chapter();
chapter.Title = "Table example";
add(rpt,chapter);

table = BaseTable(magic(5));
table.Title = "Rank 5 Magic Square";
add(rpt,table);

add(rpt,Paragraph());
imgSize = {Height("2in"),Width("2in")};
img1 = Image(which("b747.jpg"));
img1.Style = imgSize;
img2 = Image(which("peppers.png"));
img2.Style = imgSize;
table = BaseTable({"Boeing 747" "Peppers"; img1, img2});
table.Title = "Picture Gallery";
add(rpt,table);

delete(gcf);
rptview(rpt);

This example shows how to customize table entries, based on the content of the entries when using an mlreportgen.report.BaseTable reporter. You can run this example only on MATLAB® version R2022a or later.

Import these packages, so that you do not have to use long, fully qualified class names.

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

Create a table with student names and grades.

Student_names = ["Charlie","Sarah","John","Teena","Alfred","Emma","Bill","Tyler"]';
Student_grades = [83,42,75,98,78,49,91,88]';
studentsTable = FormalTable(["Student Name","Student Grade"],[Student_names,Student_grades]);
studentsTable.Header.Style{end+1} = BackgroundColor("silver");
studentsTable.Width = "250pt";

Create an mlreportgen.dom.BaseTable reporter with the students table.

baseTabReporter = BaseTable(studentsTable);

Assign a handle of the callback function tabEntryUpdateCB, that is defined in the file tabEntryUpdateCB.mlx, to the TableEntryUpdateFcn property of the reporter.

Use the command edit tabEntryUpdateCB in the command line to see the code of the callback function.

baseTabReporter.TableEntryUpdateFcn = @tabEntryUpdateCB;

Create an mlreportgen.dom.Report of type PDF, then append the base table reporter to the report.

document = Report("Update_table_entries_example_report","pdf");
append(document,baseTabReporter);

Close and view the report.

close(document);
rptview(document);

Version History

Introduced in R2017b