Main Content

在页面中安装宽桌子

此示例显示了如何在报告中安装宽桌子。

此示例的数据是一个垫子文件,其中包含来自德克萨斯州奥斯汀的流量摄像头数据的单元格数组。该单元格数组包含诸如相机位置,状态和打开日期等信息等。

我们假设包含流量摄像机数据的单元格数组的trigical_data.mat文件在当前工作目录中。要求是打印桌子,以便其所有圆柱都适合8.5英寸宽乘11英寸的纸张,在肖像方向上。

创建一个表:

To include a table in a report, use mlreportgen.dom.FormalTable object. This object has a table body and an optional table header and footer.

首先,将包含MATLAB单元阵列数据数据的垫子文件加载到工作区。使用单元格数数据创建DOM正式表对象。要使表更易于阅读,请将表标题设置为粗体,并在表列分隔符和表内容之间添加左边的边距空间。

加载('traffic_data.mat');tbl_header = traffic_camera_data(1,:); traffic_camera_data(1,:) = []; formalTable = mlreportgen.dom.FormalTable(tbl_header,traffic_camera_data); formalTable.RowSep =“坚硬的”;正式table.colsep =“坚硬的”;为了malTable.Border =“坚硬的”;formortable.header.tableentriesstyle = [formartable.header.tableentriesstyle,...{mlReportgen.dom.bold(true)}];formortable.tableentriesstyle = [formartable.tableentriesstyle,...{mlreportgen.dom.innermargin("2pt",,,,"2pt",,,,"2pt",,,,"2pt"),...mlreportgen.dom.whitespace("preserve")}];

Trial Number 1:在尺寸8.5英寸宽和11英寸长的默认肖像页面中添加DOM正式表。

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

进口mlreportgen.dom。*进口mlReportgen.Report。*;

创建一个容器来保存报告内容。

%要创建单词报告,请将输出类型从“ PDF”更改为“ DOCX”。rpt =报告(“交通CamerAdataportrait”,,,,“ PDF”);

Create a chapter with the title "Traffic Cameras in Austin".

章=章节(“标题”,,,,“奥斯丁的交通摄像头”);

Add the created table to the chapter and add the chapter to the report.

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

Result: The generated report includes the table but the table columns are too narrow. Fitting the whole table in a portrait page created a table that is not legible.

Trial Number 2:将宽桌子安装在面向景观的页面中,该页面宽11英寸乘8.5英寸。

进口mlreportgen.dom。*进口mlReportgen.Report。*;进口mlreportgen.utils。*rpt =报告(“交通Cameradatalandscape”,,,,“ PDF”);章=章节(“标题”,,,,“奥斯丁的交通摄像头”);

将报告景观布局设置为真。将表添加到本章中。

rpt.layout.landscape = true;添加(章节,正式);添加(RPT,章);关闭(RPT);

Result: Although the landscape layout is better than the portrait page report, many columns are not legible and the table is not easy to read.

Trial Number 3: Use the Report Generator TableSlicer utility to slice the input table into multiple slices. Its MaxCols property specifies the maximum number of columns per table slice.

First, try dividing the table into two slices and print them on default 8.5 wide by 11 inch long portrait paper.

进口mlreportgen.dom。*进口mlReportgen.Report。*;进口mlreportgen.utils。*rpt =报告("TrafficCameraDataSlicing-1",,,,“ PDF”);章=章节(“标题”,,,,“奥斯丁的交通摄像头”);

Now, create a table slicer object and specify the formal table as an input . The input table has 18 columns, so to create two slices, set the MaxCols property to 9.

表切片机实用程序具有切片方法,该方法切片表并生成mlreportgen.utils.tableslice对象。这些对象具有切片表以及原始输入表的启动和最终列索引。

slicer = mlreportgen.utils.TableSlicer("Table",,,,为了malTable,"MaxCols",,,,9); slices = slicer.slice();

Use the start and end index to create a customized title. Then add the customized sliced table title and the table slice to the chapter.

为了slice = slices str = sprintf(“从列%d到列%d”,slice.startcol,slice.endcol);para =段落(str);para.bold = true;para.style = [para.Style,{keepwithNext(true),...OuterMargin(“ 0pt”,,,,“ 0pt”,,,,“ 5pt”,,,,“ 0pt”)}];添加(第章,第2章);添加(章,slice.table);结尾

Generate and display the report.

添加(RPT,章);关闭(RPT);

Result: The output is better than first two trials, but the table slices are difficult to read and are disconnected from each other.

Trial Number 4:基于试验输出到目前为止,减少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.

进口mlreportgen.dom。*进口mlReportgen.Report。*;进口mlreportgen.utils。*rpt =报告("TrafficCameraDataSlicing-2",,,,“ PDF”);章=章节(“标题”,,,,“奥斯丁的交通摄像头”);

将maxcols值设置为6,然后将reovercols值设置为1。

slicer = mlreportgen.utils.TableSlicer("Table",,,,为了malTable,"MaxCols",,,,...6,,"RepeatCols",1);slices = slicer.slice();

Create a customized title using the start and end index. Add the customized sliced table title and the table slice to the chapter.

为了slice = slices str = sprintf("Repeated Column Index: %d ,SlicedColumns: From column %d to column %d",,,,...slicer.RepeatCols,slice.StartCol, slice.EndCol); para = Paragraph(str); para.Bold = true; para.Style = [para.Style,{KeepWithNext(true),...OuterMargin(“ 0pt”,,,,“ 0pt”,,,,“ 5pt”,,,,“ 0pt”)}];添加(第章,第2章);添加(章,slice.table);结尾

Generate and display the report.

添加(RPT,章);关闭(RPT);rptview(rpt);

结果:输出是清晰的,它满足了在肖像页面上打印桌子的原始要求。输入表样式具有大胆的标头和内部边缘,这些样式都保留在所有表切片中。

自定义表瓷砖,供读者理解表条目数据。

Copyright 2018 The MathWorks, Inc