2012-04-09 37 views
5

Tôi đã tạo ba trường văn bản trong Tiêu đề. Tôi đã đặt tham số trong tất cả các phần tử textField. Khi tôi không gọi một trong ba tham số của ba yếu tố textField. Nó sẽ hiển thị 2 thành phần textField. Vấn đề bây giờ là có không gian giữa các trường văn bản.Làm thế nào để loại bỏ thêm không gian giữa textfield trong JasperReports?

Cách xóa không gian?

Đây là mã của tôi:

<textField isBlankWhenNull="true"> 
    <reportElement x="0" y="18" width="555" height="35" isRemoveLineWhenBlank="true"/> 
    <textElement textAlignment="Center"> 
     <font size="12"/> 
    </textElement> 
    <textFieldExpression><![CDATA[$P{daterangefrom} && $P{daterangeto} ? "From (" + $P{daterangefrom} + " - " + $P{daterangeto} + ")" 
: $P{weeks} && $P{monthy} && $P{yrs} ? "For week " + $P{weeks} +" "+ $P{monthy} +" "+ $P{yrs} 
: $P{monthy} && $P{yrs} ? "For monthly " +$P{monthy} +" "+ $P{yrs} 
: $P{quarter} && $P{yrs} ? "For Quarter " + $P{quarter} +" "+$P{yrs} 
: $P{yrs} ? "For " + $P{yrs} 
: null]]> 
    </textFieldExpression> 
</textField> 

Đây là kết quả của tôi:

enter image description here

+0

Bạn có thể sử dụng một 'textField'. Bạn đang sử dụng loại vị trí nào (theo chiều dọc hoặc chiều ngang)? –

+0

im sử dụng vertical.ydays, tôi đang sử dụng kết hợp tất cả trong một textfield và tôi đặt đường đôi. khi một trong ba không hiển thị. nó sẽ hiển thị 2 textfield. nhưng có không gian trong textfield. cách xóa không gian để báo cáo có thể hiển thị cấu trúc hơn? –

Trả lời

14

Bạn có thể sử dụng 3 textField yếu tố với isRemoveLineWhenBlank bất động sản thiết lập để giá trị true.

Mẫu (jrxml tập tin):

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport .. topMargin="0" bottomMargin="0"> 
    <parameter name="parameter1" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <parameter name="parameter2" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <parameter name="parameter3" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <title> 
     <band height="102" splitType="Stretch"> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="163" y="9" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{parameter1} == null ? null : "Parameter1: " + $P{parameter1}]]></textFieldExpression> 
      </textField> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="163" y="29" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{parameter2} == null ? null : "Parameter2: " + $P{parameter2}]]></textFieldExpression> 
      </textField> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="163" y="49" width="100" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{parameter3} == null ? null : "Parameter3: " + $P{parameter3}]]></textFieldExpression> 
      </textField> 
      <staticText> 
       <reportElement x="163" y="73" width="100" height="20"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <text><![CDATA[Static text]]></text> 
      </staticText> 
      <line> 
       <reportElement x="63" y="6" width="447" height="1"/> 
      </line> 
      <line> 
       <reportElement x="73" y="96" width="447" height="1"/> 
      </line> 
     </band> 
    </title> 
</jasperReport> 

Thiết kế báo cáo trong iReport: Report's design in iReport

Đối với argument1 = null, argument2 = null, argument1 = VALUE3 kết quả sẽ là: The result in iReport (preview mode)

CẬP NHẬT

Đối với việc giải quyết vấn đề di chuyển lên textField trong trường hợp các yếu tố trên đã giấu bạn có thể sử dụng container Frame.Bạn nên thêm 2 khung hình (một khung cho mỗi cột) và đặt các thành phần 2 textField (2 hàng) vào mỗi khung.

Mẫu (jrxml tập tin):

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport .. topMargin="0" bottomMargin="0"> 
    <parameter name="par1" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <parameter name="par2" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <parameter name="par3" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <parameter name="par4" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[null]]></defaultValueExpression> 
    </parameter> 
    <title> 
     <band height="80" splitType="Stretch"> 
      <line> 
       <reportElement x="10" y="6" width="520" height="1"/> 
      </line> 
      <line> 
       <reportElement x="10" y="72" width="520" height="1"/> 
      </line> 
      <frame> 
       <reportElement x="329" y="10" width="172" height="59"/> 
       <frame> 
        <reportElement x="13" y="3" width="60" height="54"/> 
        <textField isBlankWhenNull="true"> 
         <reportElement x="1" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/> 
         <box> 
          <topPen lineWidth="1.0"/> 
          <leftPen lineWidth="1.0"/> 
          <bottomPen lineWidth="1.0"/> 
          <rightPen lineWidth="1.0"/> 
         </box> 
         <textElement/> 
         <textFieldExpression><![CDATA[$P{par3} == null ? null : "P3: " + $P{par3}]]></textFieldExpression> 
        </textField> 
        <textField isBlankWhenNull="true"> 
         <reportElement x="1" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/> 
         <box> 
          <topPen lineWidth="1.0"/> 
          <leftPen lineWidth="1.0"/> 
          <bottomPen lineWidth="1.0"/> 
          <rightPen lineWidth="1.0"/> 
         </box> 
         <textElement/> 
         <textFieldExpression><![CDATA[$P{par1} == null ? null : "P1: " + $P{par1}]]></textFieldExpression> 
        </textField> 
       </frame> 
       <frame> 
        <reportElement x="73" y="3" width="70" height="54"/> 
        <textField isBlankWhenNull="true"> 
         <reportElement x="1" y="0" width="52" height="20" isRemoveLineWhenBlank="true"/> 
         <box> 
          <topPen lineWidth="1.0"/> 
          <leftPen lineWidth="1.0"/> 
          <bottomPen lineWidth="1.0"/> 
          <rightPen lineWidth="1.0"/> 
         </box> 
         <textElement/> 
         <textFieldExpression><![CDATA[$P{par2} == null ? null : "P2: " + $P{par2}]]></textFieldExpression> 
        </textField> 
        <textField isBlankWhenNull="true"> 
         <reportElement x="1" y="20" width="52" height="20" isRemoveLineWhenBlank="true"/> 
         <box> 
          <topPen lineWidth="1.0"/> 
          <leftPen lineWidth="1.0"/> 
          <bottomPen lineWidth="1.0"/> 
          <rightPen lineWidth="1.0"/> 
         </box> 
         <textElement/> 
         <textFieldExpression><![CDATA[$P{par4} == null ? null : "P4: " + $P{par4}]]></textFieldExpression> 
        </textField> 
       </frame> 
      </frame> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="10" y="30" width="52" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{par3} == null ? null : "P3: " + $P{par3}]]></textFieldExpression> 
      </textField> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="10" y="10" width="52" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{par1} == null ? null : "P1: " + $P{par1}]]></textFieldExpression> 
      </textField> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="64" y="10" width="52" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{par2} == null ? null : "P2: " + $P{par2}]]></textFieldExpression> 
      </textField> 
      <textField isBlankWhenNull="true"> 
       <reportElement x="64" y="30" width="52" height="20" isRemoveLineWhenBlank="true"/> 
       <box> 
        <topPen lineWidth="1.0"/> 
        <leftPen lineWidth="1.0"/> 
        <bottomPen lineWidth="1.0"/> 
        <rightPen lineWidth="1.0"/> 
       </box> 
       <textElement/> 
       <textFieldExpression><![CDATA[$P{par4} == null ? null : "P4: " + $P{par4}]]></textFieldExpression> 
      </textField> 
     </band> 
    </title> 
</jasperReport> 

Thiết kế báo cáo trong iReport: The design in iReport. Two cases

Đối với par1 = null, par2 = 2, par3 = 3, par4 = 4 sự kết quả sẽ là: The result in iReport preview. Two cases

Bạn có thể so sánh kết quả - bên trái được thực hiện mà không cần sử dụng frame và bên phải có các thành phần frame.

+0

@Amin Chỉ cần thêm ảnh chụp màn hình thiết kế của báo cáo –

+0

Cảm ơn bạn @Alex k. nhưng tôi có thêm một câu hỏi, nếu tôi đặt tổng cộng 4 TextField. tôi đặt 2 textfield tại dòng 1 và 2 textfield ở dòng 2. làm thế nào để loại bỏ các không gian nếu loại bỏ một textfield trong dòng 1 ?. –

+1

Ví dụ bạn có 'txtFieldName1' và' txtFieldValue1' ở hàng đầu tiên và 'txtFieldName2' và' txtFieldValue2' ở hàng thứ hai (dòng). Nếu biểu thức của phần tử 'txtFieldName1' là null, bạn có muốn ẩn cả hai phần tử (' txtFieldName1' và 'txtFieldValue1') và chỉ hiển thị một hàng (với các phần tử' txtFieldName2' và 'txtFieldValue2') trong trường hợp này hay bạn muốn để hiển thị 'txtFieldName2' và' txtFieldValue1' ở hàng đầu tiên và chỉ 'txtFieldValue2' ở hàng thứ hai? Bạn có thể giải thích cho tôi quy tắc? –

1

Có rất nhiều cách để giải quyết vấn đề như thế này, nhưng trừ khi bạn cung cấp thông tin chi tiết về báo cáo của bạn . Tôi thực sự không thể đưa ra một số gợi ý tốt.

Nhưng dưới đây là một số mẹo có thể giúp bạn.

Sử dụng một TextField và một tham số.

Thay vì soạn tiêu đề của bạn bằng jrxml với riêng biệt TextField, trước tiên bạn có thể soạn nó theo số Java, sau đó lưu trữ làm tham số. Bằng cách này, bạn có thể thực hiện Java giúp bạn với tất cả các logic về việc soạn chuỗi.

Sử dụng một TextField và ba thông số

Bạn chỉ có thể viết các biểu thức như thế này trong TextField

để bạn có thể ngăn chặn sự chênh lệch gây ra bởi rỗng TextField. Hoặc sử dụng biểu thức điều kiện viết tắt như thế này.

$P{FirstName} + (${MiddleName}.isEmpty() ? "" : " " + ${MiddleName}) + " " + ${LastName} 
+0

Bạn có thể cập nhật mã của mình thành câu hỏi không? bình luận không phải là một nơi tốt để đọc mã. Và vui lòng ** giải thích vấn đề của bạn **, giống như kết quả bạn mong đợi báo cáo của bạn trông như thế nào, nhưng bây giờ nó trông như thế nào. –

+0

tôi đã đặt mã và tôi thay đổi báo cáo thành javascript, đây là hình ảnh của tôi, http://i.stack.imgur.com/guooK.jpg –

Các vấn đề liên quan