Main Content

创建斑马条纹的表

此示例显示了如何使用交替的颜色行或列创建表。这些表被称为斑马条纹或带状桌子。要在报告中创建斑马条纹的表,您可以在程序或模板中定义它。本节中的示例具有斑马条纹的行。使用类似的技术对斑马条纹柱。

报告生成器API支持以编程方式或使用Word或HTM金宝appL模板来创建斑马分纹表。您不能使用PDF模板为斑马条纹表创建PDF报告。

斑马条纹的表使用程序

该程序创建了8 x 8魔法方形桌。它具有在蓝色和白色之间交替的行背景颜色,这有助于阅读和求和行。该程序还包括为行高度,表格宽度,边界和单元条目对齐的格式化。

进口mlReportgen.Report。*进口mlreportgen.dom。*rpt =报告('zebratable',,,,'PDF');maglen = 8;mag =魔术(Maglen);tb = table(mag);%设置交替行的颜色为了i = 1:maglen r = tb.row(i);如果mod(i,2)== 0 r.Style = {backgroundColor(“ LightSteelBlue”)};别的r.Style = {backgroundColor('白色的')};结尾结尾tb.Style = {rowheight('0.3in'),rowsep('坚硬的'),ColSep('坚硬的')};tb.width ='3in';tb.TableEntriesVAlign ='中间';tb.tableentrieshalign ='中央';tb.border ='单身的';add(rpt,tb) close(rpt) rptview(rpt)

使用单词模板的斑马条纹表

此示例显示了如何将表样式添加到定义斑马条纹表的单词模板中。使用模板模块化您的应用程序。您可以更新模板,而不是更新可能引入错误的程序。

1. Open a Word template. In this example, the template file is myrpt.dotx, which you can create usingmlreportgen.report.Report.createTemplate('myrpt','docx')。To open a Word template file, right-click the file and then, click Open in the menu. (If you click the file directly, a .doc file that uses that template opens.)

2.打开Stylespane as shown.

3. In the Styles pane, click theNew Stylebutton.

4.定义表格样式,指定或选择the field values. To match the programmatic zebra-striped table example, set these fields to apply the features to the table and table rows:

  • 姓名- 添加斑马筋作为样式的名称。使用此样式名称来指定程序中的表格。

  • 样式类型-Table

  • 将格式应用于-甚至是串行的行

  • Color field(No Color)-选择a color for the odd banded rows from the dropdown.

Then, set these fields to apply these additional features to the whole table:

  • 将格式应用于-整表

  • 结盟 -Align Center

  • 边界 -All Borders

5.点击OKto save the new style.

6.保存模板文件

7. In your program, specify the template file to use, and then, you can apply the new zebra-stripe style to a table in your program.

rpt = mlreportgen.dom.Document('我的报告',,,,'docx',,,,'myrpt.dotx');tb = Table(); tb.StyleName ='ZebraStripeTable';

Not all formatting options that you can use in a program are available in Word. For this example to match the programmatic example, in addition to specifying styles in the Word template, you must specify the row height and table width in your program.

tb.Style = {rowheight('0.3in')};tb.width ='3in';

这是使用单词模板的完整代码,myrpt。dotx,将魔术正方形格式化为斑马条纹的桌子。

进口mlReportgen.Report。*进口mlreportgen.dom。*rpt = mlreportgen.report.Report('我的报告',,,,'docx',,,,'myrpt.dotx');maglen = 8;mag =魔术(Maglen);tb = table(mag);TB.Stylename ='ZebraStripeTable';tb.Style = {rowheight('0.3in')};tb.width ='3in';添加(RPT,TB)关闭(RPT);RPTView(RPT)

使用HTML模板使用斑马条纹的表

此示例显示了如何将表样式添加到定义斑马条纹表的HTML模板中。使用模板模块化您的应用程序。您可以更新模板,而不是更新可能引入错误的程序。

1.如果您没有现有的HTML模板,请使用mlreportgen.report.Report.createTemplate('myrpt','html')。In this example, the template file is in a zipped template package,myrpt.htmtx

2.使用unzipTemplate('myrpt.htmtx')解解压缩模板以创建一个名称的文件夹myrpt,,,,which contains the style sheets and image template files.

3. Go to the stylesheets folder in themyrpt文件夹。打开root.css在文本编辑器中文件。

4.创建一个CSS规则,该规则定义了针对HTML表元素的样式名称Zebrastripetet。要定义Zebrastripetable样式的CSS规则,请在root.css文件。背景颜色#B0C4DE和#FFFFFF分别为浅蓝色和白色。

/* Settings for whole table */ table.ZebraStripeTable { text-align: center; border: 1px solid black; border-collapse: collapse; width: 5in; height: 4in; } /* Settings for table body */ table.ZebraStripeTable td { padding: 0pt 0pt 0pt 0pt; vertical-align: middle; text-align: center; border: 1px solid black; border-collapse: collapse; } /* Zebra rows and colors */ tr:nth-child(even) { background-color: #B0C4DE } tr:nth-child(odd) { background-color: #FFFFFF }

5.保存root.css文件。

6. UseZiptemplate('Myrpt')将模板文件缩回myrpt.htmtxtemplate package.

7. In your program, specify ZebraStripedTable as the style of your table.

rpt = mlreportgen.report.Report('我的报告',,,,'html',,,,'myrpt.htmtx');tb = Table(); tb.StyleName ='ZebraStripeTable';

这是使用HTML模板的完整代码,myrpt.htmtx,将魔术正方形格式化为斑马条纹的桌子。

进口mlReportgen.Report。*进口mlreportgen.dom。*rpt = mlreportgen.report.Report('我的报告',,,,'html',,,,'myrpt.htmtx');maglen = 8;mag =魔术(Maglen);tb = table(mag);TB.Stylename ='ZebraStripeTable';添加(RPT,TB);关闭(RPT);RPTView(RPT);