Main Content

mlreportgen.utils.TableSlicer Class

Namespace: mlreportgen.utils

Divide table into slices

Description

Divides a table vertically into a set of narrower tables (slices). To divide a table that is too wide to fit legibly on a page into a set of legible slices, use this TableSlicer object.

The mlreportgen.utils.TableSlicer class is a handle class.

Creation

Description

slicer = mlreportgen.utils.TableSlicer creates an empty table slicer object. Use its properties to specify the input table to slice, the maximum number of columns per slice, and the number of columns to repeat.

Note

To slice a table generated by the mlreportgen.report.BaseTable reporter, set the MaxCols property of the BaseTable reporter to the size of the slices you want to generate. You do not need to use this TableSlicer utility to set the slice width.

slicer = mlreportgen.utils.TableSlicer(Name=Value) creates a table slicer object with additional options specified by one or more Name=Value pair arguments. Name is the property name and Value is the corresponding value. You can specify several name-value pair arguments in any order as Name1=Value1,...,NameN=ValueN.

example

Properties

expand all

Input table object to be sliced, specified as a DOM Table object or Formal Table object. For both DOM Table and Formal Table inputs, the table must have the same number of columns in each row. Its RowSpan and ColSpan values must be empty [] or 1. If a Formal Table object has headers or footers, the number of header or footer columns must match the number of columns in the table body.

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 can cause illegible tables to be generated. 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.

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.

Methods

expand all

Examples

collapse all

Create a FormalTable object that contains employee data. Slice the table so that the first table column repeats in each slice and the maximum number of columns in each slice is three.

employee_data = {...
   'Joe Smith','3/12/06','Engineer','A302';...
   'Mary Jones','4/17/03','Writer','C312';...
   'John Johnson','9/5/12','Sr. Programmer','A421';...
   'Susan White','6/29/16','Sr. Engineer','B201';...
   'Thomas Lee','10/1/17','QE Engineer','C200'};
tbl_header = {'Name','Hire Date','Position','Office'};


import mlreportgen.report.*
import mlreportgen.dom.*
import mlreportgen.utils.*
     
rpt = mlreportgen.report.Report("Sliced Table",'pdf');
open(rpt);

chapter = Chapter("Title",'Employee Report');
table = FormalTable(tbl_header,employee_data);
table.Border = 'Solid';
table.RowSep = 'Solid';
table.ColSep = 'Solid';

para = Paragraph(['The table is sliced into two tables, '...
   'with the first column repeating in each table.']);
para.Style = {OuterMargin('0in','0in','0in','12pt')};
para.FontSize = '14pt';
add(chapter,para)

slicer = TableSlicer("Table",table,"MaxCols",3,"RepeatCols",1);
totcols = slicer.MaxCols - slicer.RepeatCols;
slices = slicer.slice();
for slice=slices
     str = sprintf('%d repeating column and up to %d more columns',...
          slicer.RepeatCols,totcols);
     para = Paragraph(str);
     para.Bold = true;
     add(chapter,para)
     add(chapter,slice.Table)
end

add(rpt,chapter)
close(rpt)
rptview(rpt)

Version History

Introduced in R2018b