Sfoglia il codice sorgente

映射detail
自动换行
设置边框,staticText、textField高*1.2,Reference/@type=SpecialVarField

sunyj 8 anni fa
parent
commit
204a07c056
1 ha cambiato i file con 234 aggiunte e 14 eliminazioni
  1. 234 14
      src/main/resources/crystal2jasper.xsl

+ 234 - 14
src/main/resources/crystal2jasper.xsl

@@ -2,7 +2,7 @@
 <xsl:stylesheet version="1.0"
 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inet="http://www.inetsoftware.de">
 	<xsl:output method="xml" version="1.0" encoding="UTF-8"
-		indent="yes" cdata-section-elements="parameterDescription queryString text" />
+		indent="yes" cdata-section-elements="parameterDescription queryString text textFieldExpression" />
 	<xsl:template match="inet:Report">
 		<xsl:variable name="positionRate">
 			15
@@ -102,13 +102,18 @@
 												<xsl:value-of select="round(@width div $positionRate)" />
 											</xsl:attribute>
 											<xsl:attribute name="height">
-												<xsl:value-of select="round(@height div $positionRate)" />
+												<xsl:value-of select="round(@height div $positionRate * 1.2)" />
 											</xsl:attribute>
 										</reportElement>
 										<!-- border -->
-										<!-- <box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2"> 
-											<pen lineWidth="0.2" /> <topPen lineWidth="0.2" /> <leftPen lineWidth="0.2" 
-											/> <bottomPen lineWidth="0.2" /> <rightPen lineWidth="0.2" /> </box> -->
+										<box topPadding="2" leftPadding="2" bottomPadding="2"
+											rightPadding="2">
+											<pen lineWidth="0.2" />
+											<topPen lineWidth="0.2" />
+											<leftPen lineWidth="0.2" />
+											<bottomPen lineWidth="0.2" />
+											<rightPen lineWidth="0.2" />
+										</box>
 										<!-- align -->
 										<textElement verticalAlignment="Middle">
 											<xsl:variable name="textAlignment"
@@ -126,8 +131,10 @@
 											<!-- font -->
 											<font fontName="Microsoft YaHei UI">
 												<!-- font size -->
-												<xsl:attribute name="size"><xsl:value-of
-													select="round(Element/Element/FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												<xsl:if test="FontProperties/FontSize">
+													<xsl:attribute name="size"><xsl:value-of
+														select="round(Element/Element/FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												</xsl:if>
 												<!-- font style -->
 												<xsl:variable name="fontStyle"
 													select="Element/Element/FontProperties/FontStyle/@value"></xsl:variable>
@@ -173,9 +180,19 @@
 												<xsl:value-of select="round(@width div $positionRate)" />
 											</xsl:attribute>
 											<xsl:attribute name="height">
-												<xsl:value-of select="round(@height div $positionRate)" />
+												<xsl:value-of select="round(@height div $positionRate * 1.2)" />
 											</xsl:attribute>
 										</reportElement>
+										<!-- border -->
+										<box topPadding="2" leftPadding="2" bottomPadding="2"
+											rightPadding="2">
+											<pen lineWidth="0.2" />
+											<topPen lineWidth="0.2" />
+											<leftPen lineWidth="0.2" />
+											<bottomPen lineWidth="0.2" />
+											<rightPen lineWidth="0.2" />
+										</box>
+										<!-- align -->
 										<textElement verticalAlignment="Middle">
 											<xsl:variable name="textAlignment"
 												select="CommonProperties/HorizontalAlign/@value"></xsl:variable>
@@ -192,8 +209,10 @@
 											<!-- font -->
 											<font fontName="Microsoft YaHei UI">
 												<!-- font size -->
-												<xsl:attribute name="size"><xsl:value-of
-													select="round(FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												<xsl:if test="FontProperties/FontSize">
+													<xsl:attribute name="size"><xsl:value-of
+														select="round(FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												</xsl:if>
 												<!-- font style -->
 												<xsl:variable name="fontStyle"
 													select="FontProperties/FontStyle/@value"></xsl:variable>
@@ -226,11 +245,18 @@
 											<textFieldExpression>
 												<xsl:choose>
 													<xsl:when test="$type='DatabaseField'">
-														$F{<xsl:value-of select="substring-after($value,'.')"></xsl:value-of>}
+														<xsl:value-of
+															select="concat('$F{',substring-after($value,'.'),'}')"></xsl:value-of>
 													</xsl:when>
 													<xsl:when test="$type='FormulaField'">
-														<xsl:value-of select="$value"></xsl:value-of>
+														<xsl:value-of select="concat('@FormulaField ',$value)"></xsl:value-of>
+													</xsl:when>
+													<xsl:when test="$type='SpecialVarField'">
+														<xsl:value-of select="concat('@SpecialVarField ',$value)"></xsl:value-of>
 													</xsl:when>
+													<xsl:otherwise>
+														<xsl:value-of select="concat('@Unknown ',$value)"></xsl:value-of>
+													</xsl:otherwise>
 												</xsl:choose>
 											</textFieldExpression>
 										</xsl:if>
@@ -242,10 +268,204 @@
 				</pageHeader>
 			</xsl:if>
 
+			<!-- detail -->
+			<xsl:if test="AreaPair[@type='DetailArea']/Area[@type='Detail']">
+				<detail>
+					<band splitType="Prevent">
+						<xsl:attribute name="height"><xsl:value-of
+							select="round(AreaPair[@type='DetailArea']/Area[@type='Detail']/Section/@height div $positionRate)" /></xsl:attribute>
+						<xsl:for-each
+							select="AreaPair[@type='DetailArea']/Area[@type='Detail']/Section/Element">
+							<xsl:variable name="type" select="@type"></xsl:variable>
+							<xsl:choose>
+								<xsl:when test="$type='Box'"></xsl:when>
+								<xsl:when test="$type='Line'"></xsl:when>
+								<!-- staticText -->
+								<xsl:when test="$type='Text'">
+									<staticText>
+										<reportElement mode="Opaque">
+											<!-- position -->
+											<xsl:attribute name="x">
+												<xsl:value-of select="round(@x_position div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="y">
+												<xsl:value-of select="round(@y_position div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="width">
+												<xsl:value-of select="round(@width div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="height">
+												<xsl:value-of select="round(@height div $positionRate * 1.2)" />
+											</xsl:attribute>
+										</reportElement>
+										<!-- border -->
+										<box topPadding="2" leftPadding="2" bottomPadding="2"
+											rightPadding="2">
+											<pen lineWidth="0.2" />
+											<topPen lineWidth="0.2" />
+											<leftPen lineWidth="0.2" />
+											<bottomPen lineWidth="0.2" />
+											<rightPen lineWidth="0.2" />
+										</box>
+										<!-- align -->
+										<textElement verticalAlignment="Middle">
+											<xsl:variable name="textAlignment"
+												select="CommonProperties/HorizontalAlign/@value"></xsl:variable>
+											<!-- horizontal align -->
+											<xsl:if test="$textAlignment">
+												<xsl:attribute name="textAlignment">
+													<xsl:choose>
+														<xsl:when test="$textAlignment='1'">Left</xsl:when>
+														<xsl:when test="$textAlignment='2'">Center</xsl:when>
+														<xsl:when test="$textAlignment='3'">Right</xsl:when>
+													</xsl:choose>
+												</xsl:attribute>
+											</xsl:if>
+											<!-- font -->
+											<font fontName="Microsoft YaHei UI">
+												<!-- font size -->
+												<xsl:if test="FontProperties/FontSize">
+													<xsl:attribute name="size"><xsl:value-of
+														select="round(Element/Element/FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												</xsl:if>
+												<!-- font style -->
+												<xsl:variable name="fontStyle"
+													select="Element/Element/FontProperties/FontStyle/@value"></xsl:variable>
+												<xsl:choose>
+													<xsl:when test="$fontStyle mod 4 ='1'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='2'">
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='3'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+												</xsl:choose>
+												<!-- font underline -->
+												<xsl:if test="Element/Element/FontProperties/Underline/@value">
+													<xsl:attribute name="isUnderline">true</xsl:attribute>
+												</xsl:if>
+												<!-- font strikethrough -->
+												<xsl:if test="Element/Element/FontProperties/Strikeout/@value">
+													<xsl:attribute name="isStrikeThrough">true</xsl:attribute>
+												</xsl:if>
+											</font>
+										</textElement>
+										<text>
+											<xsl:value-of select="Element/Element/TextData" />
+										</text>
+									</staticText>
+								</xsl:when>
+								<!-- textField -->
+								<xsl:when test="$type='FieldElement'">
+									<textField isStretchWithOverflow="true"
+										isBlankWhenNull="true">
+										<reportElement stretchType="RelativeToTallestObject" mode="Opaque">
+											<!-- position -->
+											<xsl:attribute name="x">
+												<xsl:value-of select="round(@x_position div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="y">
+												<xsl:value-of select="round(@y_position div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="width">
+												<xsl:value-of select="round(@width div $positionRate)" />
+											</xsl:attribute>
+											<xsl:attribute name="height">
+												<xsl:value-of select="round(@height div $positionRate * 1.2)" />
+											</xsl:attribute>
+										</reportElement>
+										<!-- border -->
+										<box topPadding="2" leftPadding="2" bottomPadding="2"
+											rightPadding="2">
+											<pen lineWidth="0.2" />
+											<topPen lineWidth="0.2" />
+											<leftPen lineWidth="0.2" />
+											<bottomPen lineWidth="0.2" />
+											<rightPen lineWidth="0.2" />
+										</box>
+										<!-- align -->
+										<textElement verticalAlignment="Middle">
+											<xsl:variable name="textAlignment"
+												select="CommonProperties/HorizontalAlign/@value"></xsl:variable>
+											<!-- horizontal align -->
+											<xsl:if test="$textAlignment">
+												<xsl:attribute name="textAlignment">
+													<xsl:choose>
+														<xsl:when test="$textAlignment='1'">Left</xsl:when>
+														<xsl:when test="$textAlignment='2'">Center</xsl:when>
+														<xsl:when test="$textAlignment='3'">Right</xsl:when>
+													</xsl:choose>
+												</xsl:attribute>
+											</xsl:if>
+											<!-- font -->
+											<font fontName="Microsoft YaHei UI">
+												<!-- font size -->
+												<xsl:if test="FontProperties/FontSize">
+													<xsl:attribute name="size"><xsl:value-of
+														select="round(FontProperties/FontSize/@value div $positionRate * 0.75)" /></xsl:attribute>
+												</xsl:if>
+												<!-- font style -->
+												<xsl:variable name="fontStyle"
+													select="FontProperties/FontStyle/@value"></xsl:variable>
+												<xsl:choose>
+													<xsl:when test="$fontStyle mod 4 ='1'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='2'">
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+													<xsl:when test="$fontStyle mod 4 ='3'">
+														<xsl:attribute name="isBold">true</xsl:attribute>
+														<xsl:attribute name="isItalic">true</xsl:attribute>
+													</xsl:when>
+												</xsl:choose>
+												<!-- font underline -->
+												<xsl:if test="FontProperties/Underline/@value">
+													<xsl:attribute name="isUnderline">true</xsl:attribute>
+												</xsl:if>
+												<!-- font strikethrough -->
+												<xsl:if test="FontProperties/Strikeout/@value">
+													<xsl:attribute name="isStrikeThrough">true</xsl:attribute>
+												</xsl:if>
+											</font>
+										</textElement>
+										<!-- textFieldExpression -->
+										<xsl:if test="Reference">
+											<xsl:variable name="type" select="Reference/@type"></xsl:variable>
+											<xsl:variable name="value" select="Reference/@value"></xsl:variable>
+											<textFieldExpression>
+												<xsl:choose>
+													<xsl:when test="$type='DatabaseField'">
+														<xsl:value-of
+															select="concat('$F{',substring-after($value,'.'),'}')"></xsl:value-of>
+													</xsl:when>
+													<xsl:when test="$type='FormulaField'">
+														<xsl:value-of select="concat('@FormulaField ',$value)"></xsl:value-of>
+													</xsl:when>
+													<xsl:when test="$type='SpecialVarField'">
+														<xsl:value-of select="concat('@SpecialVarField ',$value)"></xsl:value-of>
+													</xsl:when>
+													<xsl:otherwise>
+														<xsl:value-of select="concat('@Unknown ',$value)"></xsl:value-of>
+													</xsl:otherwise>
+												</xsl:choose>
+											</textFieldExpression>
+										</xsl:if>
+									</textField>
+								</xsl:when>
+							</xsl:choose>
+						</xsl:for-each>
+					</band>
+				</detail>
+			</xsl:if>
+
 			<!-- pageFooter -->
 			<xsl:if test="AreaPair[@type='PageAreaPair']/Area[@type='PageFooter']">
 				<pageFooter>
-					<band splitType="Stretch">
+					<band splitType="Prevent">
 						<xsl:attribute name="height"><xsl:value-of
 							select="round(AreaPair[@type='PageAreaPair']/Area[@type='PageFooter']/Section/@height div $positionRate)" /></xsl:attribute>
 					</band>
@@ -255,7 +475,7 @@
 			<!-- summary -->
 			<xsl:if test="AreaPair[@type='ReportAreaPair']/Area[@type='ReportFooter']">
 				<summary>
-					<band>
+					<band splitType="Prevent">
 						<xsl:attribute name="height"><xsl:value-of
 							select="round(AreaPair[@type='ReportAreaPair']/Area[@type='ReportFooter']/Section/@height div $positionRate)" /></xsl:attribute>
 					</band>