XML Publisher RTF模版开发技巧

Template Builder->Preview->RTF

Tag-Group

 Template的建立过程中,Group的概念很重要。
Group:一笔资料就是为一个group.
Group可以嵌套循环。
 例如:一张PO的资料包括headerline两部分。可以把这两部分HeaderLine的资料看成是一个Group,同时也可以把Line的每一笔资料做为一个Group,嵌套在Header中。
<?for-each:<group name>?>做为一个Group的开头,放在资料的第一个Field的前面。

<?end for-each?>做为一个Group的结尾,放在资料的最后一个Field的后面。

Tag-<?<Field Name>?>

 <?<Field Name>?>为一Field的引用,<Field Name>栏位名必须与XML里面的一样,区分大小写。
 在报表的执行过程中, <?<Field Name>?>将由XML里面对应的Element所取代。
Tag-<?sort:<Item_Column>?>

 <?sort:<Item_Column>?>为排序Tag
 可以使用Group中的任何Element做为排序的准则。
 如果需要多Element的排序,可以使用如下的方式

    <?sort:<Item_Column1>?><?sort:<Item_Column2>?>

 降序排序:<?sort:<Item_Column>; 'descending'?>
 升序排序:<?sort:<Item_Column>; ‘ascending'?>
 例如:<?sortPO_NUM?>将按PO单号排序 
 排序有分按Date/Text还是按Number排序。按Date/Text400将排在50前面。

  例如:<?sort:PO_NUM;'descending';data-type='text'?>

  <?sort:PO_NUM;'ascending';data-type='number'?>
Tag-Page Break
 可以使用<?split-by-page-break:?>进行分页
 Group的结束标志符<?end for-each?>前加上<?split-by-page-break:?>,当该group结束后将会自动分页,下一个group的资料将show在下一页里。
Tag-Section
 有时一张report中包含了很多资料,比如一张report中包含多张PO的资料,而页码、页面加总的要根据不同的PO进行重置。如果页眉和页脚也使用了body里面的一些元素,这时候也需要重置。
使用<?for-each@section:group name?>可以达到这样的效果
Insert an image inthe template
 url也可以XML里面的一个元素(当这个元素为完整的图片URL)

  url:{IMAGE_LOCATION}( IMAGE_LOCATIONgroup中一元素)

 url中也可以是只是一个目录而已:

  url:{’${OA_MEDIA}/image name’}( OA_MEDIA->为一个目录)

  例如:url:{’${OA_MEDIA}/ORACLE_LOGO.gif’}

 如果是多个截断的,也可以用concat这个function进行串联:
 例如:
 利用Report Builder生成.rtf报表,不需生成其layout,然后点选File ->Generate to File ->XML 生成XML文档
局格式化1.1.建议做法

充分利用Word的格式化功能纸张自定义、颜色、字号、字体、标题样式、背景、水印、对齐、表格、分栏、模版日期、窗体域的数字/日期格式、文件图片、页眉页脚、自动图文集。虽然可以代码控制,但既然依托Word作为可视化设计工具,我们就尽量使用Word功能来设计报表吧!

1.2. Word表格

和做网页一样,表格在报表布局中的地位至关重要,要熟练掌握,尤其是:

1、 标题行重复,可以实现新页重复标题。

2、 嵌套表格、行列合并、边框、底纹,可以实现特殊的布局。

3、 固定列宽、自动调整、禁止跨页断行,可以实现一些严格的布局控制。

1.3.行截断与禁止折行

单据打印中对格式的要求比较高,如果某一行过长或者出现多次折行,就会破坏版面,尤其是套打等要求较高的场合,这里把各种方法作个小结。

1.3.1 Word功能,不理想

固定列宽功能可以用,但固定行高不行,虽然设计时看到固定了,如果不加控制,运行后多出列宽的数据会自动折行。

1.3.2 单行+截断,即控制只有一行,多余截断,禁止折行

在字段后,再加两个命令:

<xsl:attribute xdofo:ctx="block" name="wrap-option">no-wrap</xsl:attribute>

<xsl:attribute xdofo:ctx="block" name="overflow">hidden</xsl:attribute>

参见:行截断与禁止折行.rtf
行截断与禁止折行.xml

1.3.2.1行不加任何控制不截段


见图2.2 ,红圈所划的地方

Industry Id

Industry

Year

Month

Sales


FINDUSTRY_ID

INDUSTRY

YEAR

MONTH

SALES
E




图2.1





图2.2

看看图2.1中各个窗体字段的帮助文本,(双击该字段,在弹出窗口中单击添加帮助文字即可查看),如表2.1


窗体字段(从上到下,从左到右) 帮助文本
F <?for-each:ROW?>
INDUSTRY_ID <?INDUSTRY_ID?>
INDUSTRY <?INDUSTRY?>
YEAR <?YEAR?>
MONTH <?MONTH?>
SALES <?SALES?>
E <?end for-each?>


表2.1

1.3.2.2行+截断,即控制只有一行,多余截断,禁止折行


显示效果,见图2.3



实现方法,见表2.2


窗体字段(从上到下,从左到右) 帮助文本
F <?for-each:ROW?>
INDUSTRY_ID <?INDUSTRY_ID?>
INDUSTRY <?INDUSTRY?>
<xsl:attribute xdofo:ctx="block" name="wrap-option">no-wrap</xsl:attribute>
<xsl:attribute xdofo:ctx="block" name="overflow">hidden</xsl:attribute>
YEAR <?YEAR?>
MONTH <?MONTH?>
SALES <?SALES?>
E <?end for-each?>

1.3.3 多行+截断,难

如固定显示3行,多余部分截断,目前通过模版无法实现,只有在数据源中先将数据截至刚好3行的字符数,然后利用自动折行功能。这里还要注意空格,如果遇到空格,后面的单词又显示不下,将会提前自动折行。

1.4.条件格式化

在不同的条件下显示不同的颜色、不同的列数、不同的标题、不同的布局风格等等,这些都属于条件格式化,需要借助IF命令。

1、比如不同币种凭证打印格式不同

<?if:CURRENCY_CODE="CNY"?>任何布局<?end if?>

<?if:CURRENCY_CODE!="CNY"?>任何布局<?end if?>

2、比如货币为CNY时才显示列,在目标列的单元格内写如下语句

<?if@column:CURRENCY_CODE="CNY"?>字段值和格式<?end if?>

注:这还不是真正的动态列。

3、比如偶数行底色为灰色,在行的任何单元格内写如下语句

<?if@rowposition() mod 2=0?>

<xsl:attribute xdofo:ctx="incontext" name="background-color">gray</xsl:attribute>

<?end if?>

4
比如超过100单元格呈红色在目标单元格内写如下语句

<?ifUANTITY>100?>

<xsl:attribute xdofo:ctx="block" name="background-color">red</xsl:attribute>

<?end if?>

2.字段计算技巧

2.1.建议做法

1
计算字段可以在SQL中先完成。

2
如果使用Oracle Reports做数据源那么计算字段、统计字段也可以先完成。

3
SQL中的数据都不带格式格式在模版中设置需要在模版中完成计算的字段必须不带格式主要指数字不能带千位符号。

2.2.组内合计

N: Template Builder/插入/字段

向导可以完成基本的统计目前支持分组内的:SumCountMinMaxAvarage

自动生成的代码示例:<?sum (QUANTITY)?>

2.3. 页内合计

要实现本页合计数,需分两步:声明合计变量、显示合计变量(可带格式)。

1、对QUANTITY进行本页合计,声明变量QTYTOTAL,注意写在QUANTITY对应的组内,不然引用不到

<?add-page-totalTYTOTAL;QUANTITY?>

2、可在任意地方显示合计数

<?show-page-totalTYTOTAL?>

那么如何实现组内+页内合计呢?

2.4. 结转合计

把上页的合计数显示到下页,与页内合计类似,需分两步:声明合计变量、显示合计变量。

用得少,可参考User GuideBrought Forward/Carried Forward Totals部分。

2.5. 累计数Running Totals

累计每行数字,实际上是这样完成的:先声明一个变量,初始化为0;累加;在需要的地方显示累计。

1、在分组标记前初始化,Set变量

<?xdoxslt:set_variable($_XDOCTX,RTotalVar, 0)?>

2、计算累计值,通常写在欲累计的字段同一单元格内,比如下面的QUANTITY

<?xdoxslt:set_variable($_XDOCTX,RTotalVar, xdoxslt:get_variable($_XDOCTX,RTotalVar) + QUANTITY)?>

3、任意地方显示累计值,Get变量

<?xdoxslt:get_variable($_XDOCTX,RTotalVar)?>

3.任何Page相关问题

3.1. 新组分页

分页是自然的,但如果想在某处强制分页如新组新页,那么可以使用Word的分页符(CTRL+ENTER快捷键),但会导致最后出现空白页;这样只能使用如下几种方式:

1、分组声明中加@section,如<?for-each@section:G_PO_HEADER?>。

2
<?end for-each?>前加<?split-by-page-break:?>这个翻译后,实际上是:

<xsl:if test="position()<last()">

<xsl:attribute name="break-before">page</xsl:attribute>

</xsl:if>

3 <?end for-each?>前加<xsl:attribute name="break-after">page</xsl:attribute>此法下RTF最后无空白页PDF有空白页。

4 <?end for-each?>前加<xsl:attribute name="break-before">page</xsl:attribute>此法下RTFPDF最后都有空白页。

3.2.条件分页、固定行分页

1
任意条件分页需要借助IF + 上面的break-after或者break-before

<?if:CURRENCY_CODE="CNY"?>

<xsl:attribute name="break-before">page</xsl:attribute>

<?end if?>

2
固定行分页需要借助IF + 上面的break-after或者break-before在行<?end for-each?>如下语句控制每页5

<?ifosition() mod 5 =0?>

<xsl:attribute name="break-before">page</xsl:attribute>

<?end if?>

3.3. 页眉页脚

1、标准的页眉页脚,即单个页眉页脚,使用Word的功能即可。

2、扩展的页眉页脚,可使用<?start:body?><?end body?>把主体部分起来,凡是在这两个标记之外的东西,都将被当作页眉页脚。

3.4. 页码和页数

1、可以用Word的自动图文集,在任意地方插入页码,这个是自然页码

2、如果在某种情况下想让页码从特定值开始,比如新的组页码重新编号,则需要借助命令,如在for-each后写:<?initial-page-number:1?>。这里的1,实际上也可以用数据文件中的XML元素来替换。

3.5. 末页、奇偶页不同

1、 Word可在页眉页脚部分实现首页不同或奇偶页不同,没法实现末页不同,即使借助代码控制,实际实现的也是末页布局不同,而非页眉页脚不同。

<?start@last-page:body?><?end body?>

报表本身仅有一页时则用<?start@last-page-first:body?><?end body?>

例子Advanced\Last Page注意布局需要独立成页即之前需要加分页符。

2
以偶数页结束主要目的是显示偶数页页眉页脚

<?section:force-page-count;end-on-even-layout?>

如果仅显示空白页则用<?section:force-page-count;end-on-even?>

3
以奇数页结束主要目的是显示奇数页页眉页脚

<?section:force-page-count;end-on-odd-layout?>

如果仅显示空白页则用<?section:force-page-count;end-on-odd?>

4.使用多媒体元素

4.1. Word功能

可以使用公式、绘图如组织结构图、线条等、艺术字、剪贴画。

如果想通过代码在有限范围内控制这些对象比如显示文字、缩放、旋转、移动、复制可参考User Guide中的Drawing, Shape and Clip Art Support

4.2. 复选框

插入复选框窗体域,因其选中代表True,不选代表False,需要我们输入条件表达式,如:0。

4.3. 下拉框

插入下拉框窗体域,定义下拉框的元素,并同样在自己键入内输入需要引用的XML标记如<%AREA_INDEX%>。这里要注意元素的顺序,因为是用顺序号和运行时的值进行匹配的,也就是XML数据中,AREA_INDEX是自然数1、2……。

4.4. 超链接

可以直接利用Word功能设置超链接,也可以在链接地址中,全部或部分引用XML数据文件中的标记,做到动态超链接:

{SUPPLIER_SITE_URL}或者

http://huajhua.leiko.com:8000/OA_MEDIA/{CURRENCY_CODE}.gif

4.5. 图片

可以直接利用Word功能插入图片,也可以仅将该图片当作占位图,在图片的设置图片格式的网站标签页内的可选文字,输入真正的图片地址:

1、来自网站的图片:url:{http://localhost:8000/OA_MEDIA/forms_logo.gif}。

2、来自EBS的图片:url:{${OA_MEDIA}/forms_logo.gif}。

3、动态指定地址:url:{IMAGE_URL}。

4、动态拼接的地址:url:{concat(SERVER,/,IMAGE_DIR,/,IMAGE_FILE)}。

5、直接来自内容为BLOB的XML元素,仅用于Data Templates

<fo:instream-foreign-object content-type="image/jpg">

<xsl:value-of select="IMAGE_ELEMENT"/>

</fo:instram-foreign-object>

4.6.图表

可使用Template Builder向导插入图表类型有条形图-垂直、条形图-水平、饼图、线形图。

向导生成的代码,可在图片的设置图片格式网站标签页内的可选文字里看到,我们可以做进一步修改。

5RTF示例汇总

5.1
组内循环
<?for-each:G_INVOICES?>
<?end for-each?>

5.2if条件
<?if:1=2?>
<?end if?>

5.3Repeatable Row Headers

If your invoices break across a page and you want to repeat the column header row this can be achieved using MSWord’s functionality.

1.
Highlight the header row

2.
Table > Table Properties

3.
Under the Row tab select the ‘Repeat as Header row at the top of each page’

If the invoices table breaks across a page the header row will be repeated.

Splitting Rows across pages

You can prevent rows splitting across a page break by using MSWord’s funtionality:

1.
Highlight the data row

2.
Table > Table Properties

3.
Under the Row tab deselect the ‘Allow row to break across pages’

Rows that would normally be split across two pages will now be moved to the second page to preserve the row data.

Allow row to break across pages打勾

llow row to break across pages
打勾

5.4.

I
Invoice Listing by Supplier 2

Now lets combine the Supplierswith their Invoices, we will create an output that lists each Supplier and then their Invoices.


Field Name Contents Description
Grp:Supplier for-each:G_VENDOR Used to loop through the Supplier members

Supplier 1
VENDOR_NAME Supplier Name

1 Long Avenue
ADDRESS Address

Grp:Invoice
<?for-each:G_INVOICE_NUM?> Used to loop through the Invoice group

1134922
<?INVOICE_NUM?> Invoice Number

1-Jan-2004
<?INVOICE_DATE?> Invoice Date

USD
<?INVOICE_CURRENCY_CODE?> Invoice Currency Code

1-Jan-2004
<?GL_DATE?> GL Date

1000.00
<?ENT_AMT?> Entered amount

1000.00
<?ACCT_AMT?> Accounted Amount

End Invoice
<?end for-each?> Ends the Invoice loop
End Supplier end for-each Ends the Supplier loop

To achieve this master/detail layout we need to nest the looping fields:

Grp: Supplier


Grp: Invoices



End Invoices

End Supplier

Below you’ll see this layout to achieve the desired finalreport layout. Of course we can use the tips and tricks mentioned in previous lessons to row stripe, row splitting, etc.

I

Grp:Supplier


Supplier: Supplier 1
Address: 1 Long Avenue


Invoice NumInvoice DateCurrGL DateEntered
Amt
Accounted
Amt

Grp:Invoice

1134922
1-Jan-2004
USD
1-Jan-2004
1000.00
1000.00

End Invoice

End Supplier


5.5.
汇总值



<?sum(ENT_AMT)?> and sum(ACCTD_AMT)?>

Grp:Supplier


Supplier: Supplier 1
Address: 1 Long Avenue


Invoice Num Invoice Date Curr GL Date Entered Amt Accounted Amt
Grp:Invoice1134922 1-Jan-2004 USD 1-Jan-2004 1000.00 1000.00End Invoice


Total for Supplier:Supplier 1
1000.00 1000.00

End Supplier


Report Total SUM_ENT_AMT



1000.00

SUM

5.6.Number Formatting


string format-number(number,format,[decimalformat])


<?format-number(ENT_AMT,"#,###.00")?>

5.7.Grouping

for-each-group:G_INVOICE_NUM;INVOICE_CURRENCY_CODE

You may need to further group your data in addition to the existing grouping, in this case we have:

SUPPLIERS

INVOICES

Rather than update the XML extraction, we can actually introduce a new group to the hierarchy in the template layer so we have:

SUPPLIERS

CURRENCY

INVOICES

We can use a new function, ‘for-each-group’ to effectively regroup the data in the template to show the invoices by currency code, we can then show summary totals at the currenct level too. In the template below you notice that it has been restructured from the previous version. There is now a new table:


<?for-each-group:G_INVOICE_NUM;INVOICE_CURRENCY_CODE?>


<?for-each:current-group()?>


ReGrp:Curr Currency: USD
Invoice NumTypeInvoice DateGL DateEntered AmtAccounted Amt
Grp:Invoice1134922
Standard
1-Jan-20041-Jan-20041000.001000.00End Invoice

Total for USD1000.001000.00
End Curr

5.8 shapes

<?for-each@shape:SALE?>

<?shape-offset-xposition()-1)*110?>

<?end for-each?>

<?shape-size-y:SERVICES div 1000;'left/bottom'?>

<?shape-size-y:SOFTWARE div 1000;'left/bottom'?>

5.9
if:position() mod 2=0

I Table 3: If you would like a striped effect on your rows this can be achieved in the template. We now use two almost identical data rows in the table. The native XSL position() function is used to assign each row a numeric value, an ‘if’ statement is then used to test the value, so at the beginning of each row we get an if statement:


1st Row: if:position() mod 2=0


2nd Row: if:position() mod 2=1

The position() function will return a number for the row of data starting at ‘1’. The mod or modulus function will return a 0 or a 1 depending on the result e.g. 2 mod 2 returns 0 and 3 mod 2 returns a 1. So we shade each row as required and add the if statement and at runtime the rows will be alternately shaded, in this case white and gray.

I

Table:3 – Row Striping


Supplier Address
Grp:SupplierSupplier 1 1 Long AvenueEndIf
IfSupplier 1 1 Long AvenueEnd

ITable 4: You can also use Word’s Table Auto Format feature to apply astyle to your tables. Highlight the table then Table >
Table AutoFormat then select the style you want from the dialog.I

Table:4 – Auto Formatting


Supplier Address
Grp:SupplierSupplier 1 1 Long AvenueEnd

5.10
Brought Forward

<?call:header?>


Call:header
是调用
<?template:header?>

<?template:header?>



Invoice Listing Report


1000 1000

<xdofo:inline-total display-condition="exceptfirst" name="EntAmt">Brought Forward: <xdofo:show-brought-forward name="EntAmt" format="99G999G999D00"/></xdofo:inline-total>

Brought Forward:本页之前的汇总值
带到下一页

<xdofo:inline-total display-condition="exceptfirst" name="EntAmt"><xdofo:show-brought-forward name="AcctAmt" format="99G999G999D00"/></xdofo:inline-total>

<?end template ?>

<?template:footer?>


Page Total: 1000 1000
<?show-page-total:EntAmt;"99G999G999D00"?> <?show-page-total:AcctAmt;"99G999G999D00"?>
1000 1000

<xdofo:inline-total display-condition="exceptlast" name="EntAmt">Carried Forward:
<
xdofo:show-carry-forward name="EntAmt" format="99G999G999D00"/></xdofo:inline-total>

<xdofo:inline-total display-condition="exceptlast" name="AcctAmt"><xdofo:show-carry-forward name="AcctAmt" format="99G999G999D00"/></xdofo:inline-total>

Carried Forward
接后,转下页、结转
forward

<?end template?>


InvoiceTypeInvoiceNumberInvoiceDateInvoiceCurrencyEntered AmountAccountedAmount
FE

INV_TYPE
13234210-May-2005USD1,000.001,000.00EG

<?call:footer?>

5.11Conditonal
条件

Setting font to bold if invoice amount greater than 1000.


InvoiceNumber Inovice Amount
Grp: Invoice13222-2 CH$100.00EFE

<?for-each:G_INVOICE_NUM?>

<?if:ACCTD_AMT>1000?><xsl:attribute xdofo:ctx="block" name="font-weight">bold</xsl:attribute><?end if?>

ACCTD_AMT》1000 的数据 字体加粗

Setting background color to green if invoice amount greater than 1000.


InvoiceNumber Inovice Amount
Grp: Invoice13222-2 CH$100.00EFE

<?if:ACCTD_AMT>1000?><xsl:attribute xdofo:ctx="block" name="background-color">lime</xsl:attribute><?end if?>


ACCTD_AMT》1000 的数据
颜色为绿色

发布了11 篇原创文章 · 获赞 3 · 访问量 9万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章