左右に並べられたイメージ
この例では、ページ上でイメージを左右に並べて配置する方法を説明します。
長い完全修飾クラス名を使用せずに済むよう、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');
対応するイメージ ファイルをラップする 2 つの image オブジェクトを作成します。以下で作成した非表示テーブルのセルに収まるように、イメージをスケーリングします。
imgStyle = {ScaleToFit(true)}; img1 = Image(which('ngc6543a.jpg')); img1.Style = imgStyle; img2 = Image(which('peppers.png')); img2.Style = imgStyle;
1 行 3 列の非表示レイアウトのテーブル (lot) の行にイメージを挿入します。
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);