主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

并排图像

此示例显示如何在页面上并排排列图像。

导入 DOM 和报告 API 包,这样您就不必使用长而完全限定的类名,然后创建报告。

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

% To create a Word report, change the output type from "pdf" to "docx". 
% To create an HTML report, change "pdf" to "html" or "html-file" for 
% a multifile or single-file report, respectively.
rpt = Report('myreport', 'pdf');

创建两个环绕相应图像文件的图像对象。缩放图像以适合下面创建的不可见表单元格。

imgStyle = {ScaleToFit(true)};
img1 = Image(which('ngc6543a.jpg'));
img1.Style = imgStyle;
img2 = Image(which('peppers.png'));
img2.Style = imgStyle;

在 1x3 的不可见布局表(很多)的行中插入图像。

lot = Table({img1, ' ', img2});

仅当指定了图像的高度和宽度时,图像的大小才会适合表条目。

lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
lot.entry(1,2).Style = {Width('.2in'), Height('3in')};
lot.entry(1,3).Style = {Width('3.2in'), Height('3in')};

使表跨越页边距之间的页面宽度。告诉表布局管理器不要调整表列的大小以适合图像。

lot.Style = {ResizeToFitContents(false), Width('100%')};

生成并显示报告。

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