主要内容

Fit Wide Tables in a Page

This example shows how to fit a wide table in a report.

这个例子是一个垫的数据文件包含cell array of traffic camera data from Austin, Texas. This cell array contains information such as camera location, its status and the date when it was turned on etc.

We assume traffic_data.mat file that contains cell array of traffic camera data is in the current working directory. The requirement is to print the table so all of its columns fit on paper that is 8.5 inches wide by 11 inches long, in portrait orientation.

Create a Table:

要在报告中包括一个表,请使用mlreportgen.dom.formaltable对象。该物体具有桌子主体和一个可选的桌子标头和页脚。

First, load a mat file containing MATLAB cell array data to workspace. Create a DOM Formal Table object using the cell array data. To make the table easier to read, set the table headings to bold, and add a left margin space between the table column separator and the table content.

load('trafcum_data.mat');tbl_header = clabine_camera_data(1,:);clumind_camera_data(1,:) = [];正式= mlReportgen.dom.formaltable(tbl_header,clumind_camera_data);正式table.rowsep ="Solid";formalTable.ColSep ="Solid";正式toble.border ="Solid";formalTable.Header.TableEntriesStyle = [formalTable.Header.TableEntriesStyle,...{mlreportgen.dom.Bold(true)}]; formalTable.TableEntriesStyle = [formalTable.TableEntriesStyle,...{mlreportgen.dom.InnerMargin(“ 2pt”,“ 2pt”,“ 2pt”,“ 2pt”),...mlreportgen.dom.WhiteSpace(“保存”)}];

试用号1: Add the DOM Formal Table in a default portrait page of size 8.5 inches wide and 11 inches long.

导入DOM并报告API软件包,因此您不必使用长的类名。

importmlreportgen.dom.*importmlreportgen.report.*;

Create a container to hold the report content.

% To create a Word report, change the output type from "pdf" to "docx".rpt = Report("TrafficCameraDataPortrait","pdf");

创建一个标题为“奥斯汀的交通摄像头”的章节。

chapter = Chapter("Title","Traffic Cameras in Austin");

将创建的表添加到本章中,并将章节添加到报告中。

添加(章节,正式);添加(RPT,章);关闭(RPT);

结果:生成的报告包括表,但表列太窄。在肖像页面中安装整个桌子,创建了一个不易读的表。

审判2: Fit the wide table in a landscape oriented page, which is 11 inches wide by 8.5 inches long.

importmlreportgen.dom.*importmlreportgen.report.*;importmlreportgen.utils.*rpt = Report("TrafficCameraDataLandscape","pdf");chapter = Chapter("Title","Traffic Cameras in Austin");

Set the report landscape layout to true. Add the table to the chapter.

rpt.Layout.Landscape = true; add(chapter,formalTable); add(rpt,chapter); close(rpt);

结果:尽管景观布局比肖像页面报告要好,但许多列都不清楚,并且表不容易阅读。

审判编号3:使用报告生成器台式程序实用程序将输入表切成多个切片。其MaxCols属性指定每个表切片的最大列数。

首先,尝试将桌子分成两个切片,然后在默认的8.5宽x 11英寸长的肖像纸上打印它们。

importmlreportgen.dom.*importmlreportgen.report.*;importmlreportgen.utils.*rpt = Report(“交通cameradataslicing-1”,"pdf");chapter = Chapter("Title","Traffic Cameras in Austin");

现在,创建一个表切片机对象,并将正式表指定为输入。输入表有18列,因此要创建两个切片,将MaxCols属性设置为9。

The table slicer utility has a slice method which slices the input table and generates mlreportgen.utils.TableSlice objects. These objects have the sliced table and the start and end column indices of the original input table.

slicer = mlreportgen.utils.tableslicer(“桌子”,正式的,“ maxcols”,9);slices = slicer.slice();

使用“开始和端”索引创建自定义标题。然后将自定义的切片表和表切片添加到本章中。

forslice = slices str = sprintf("From column %d to column %d",slice.StartCol,slice.EndCol); para = Paragraph(str); para.Bold = true; para.Style = [para.Style,{KeepWithNext(true),...outermargin("0pt","0pt","5pt","0pt")}];add(chapter,para); add(chapter,slice.Table);end

生成并显示报告。

add(rpt,chapter); close(rpt);

结果:输出比前两个试验要好,但是表切片很难读取并且彼此断开。

审判编号4:Based on the trial output so far, reduce the MaxCols value to create 4 table slices. Use the RepeatCols property to repeat columns in all the slices. To connect all 4 slices, set the RepeatCols property value to 1 so that the Camera ID column is repeated in every table slice.

importmlreportgen.dom.*importmlreportgen.report.*;importmlreportgen.utils.*rpt = Report(“交通cameradataslicing-2”,"pdf");chapter = Chapter("Title","Traffic Cameras in Austin");

Set the MaxCols value to 6 and the RepeatCols value to 1 .

slicer = mlreportgen.utils.tableslicer(“桌子”,正式的,“ maxcols”,...6,“ coptioncols”,1); slices = slicer.slice();

使用开始索引创建自定义标题。将自定义的切片表和表切片添加到本章中。

forslice = slices str = sprintf(“重复的列索引:%d,切成薄片:从列%d到列%d”,...slicer.repeatcols,slice.startcol,slice.endcol);para =段落(str);para.bold = true;para.style = [para.Style,{keepwithNext(true),...outermargin("0pt","0pt","5pt","0pt")}];add(chapter,para); add(chapter,slice.Table);end

生成并显示报告。

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

结果:Output is legible and it satisfies the original requirement to print the table on a portrait page. The input table style, which has bold headers and inner margins that are retained in all the table slices.

The table tile is customized for the readers to understand the table entries data.

版权2018 The Mathworks,Inc