我在Jasper报告中做了一个简单的报告,数据源java bean。我在报告中制作了一张桌子。在jaspersoft studio中,表格是可见的,但是当我生成报告时,表格不可见,其余条目都很好且可见。我在详细部分添加了表格
xml代码:
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles grdPlanDtl.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ItemCode As New Label()
ItemCode.ID = "ItemCode"
ItemCode.Text = TryCast(e.Row.DataItem, DataRowView).Row("ItemCode").ToString()
e.Row.Cells(1).Controls.Add(ItemCode)
ItemCode.Width = 100
Dim Description As New Label()
Description.ID = "Description"
Description.Text = TryCast(e.Row.DataItem, DataRowView).Row("Description").ToString()
e.Row.Cells(2).Controls.Add(Description)
Description.Width = 200
Dim WH As New Label()
WH.ID = "WH"
WH.Text = TryCast(e.Row.DataItem, DataRowView).Row("WH").ToString()
e.Row.Cells(3).Controls.Add(WH)
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Center
WH.Width = 10
Dim Customer As New Label()
Customer.ID = "Customer"
Customer.Text = TryCast(e.Row.DataItem, DataRowView).Row("CustName").ToString()
e.Row.Cells(4).Controls.Add(Customer)
Customer.Width = 150
Dim ST As New Label()
ST.ID = "ST"
ST.Text = FormatNumber(TryCast(e.Row.DataItem, DataRowView).Row("Std.Time").ToString(), 2)
e.Row.Cells(5).Controls.Add(ST)
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Right
ST.Width = 30
Dim TON As New Label()
TON.ID = "TON"
TON.Text = TryCast(e.Row.DataItem, DataRowView).Row("Tonnage").ToString()
e.Row.Cells(6).Controls.Add(TON)
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right
TON.Width = 40
Dim MachineNo As New Label()
MachineNo.ID = "MachineNo"
MachineNo.Text = TryCast(e.Row.DataItem, DataRowView).Row("MachineNo").ToString()
e.Row.Cells(7).Controls.Add(MachineNo)
MachineNo.Width = 50
Dim TRP As New Label()
TRP.ID = "TRP"
TRP.Text = TryCast(e.Row.DataItem, DataRowView).Row("TRP").ToString()
e.Row.Cells(10).Controls.Add(TRP)
TRP.Width = 50
Dim FixedMachine As New Label()
Dim strFix As String
FixedMachine.ID = "FixedMachine"
FixedMachine.Text = TryCast(e.Row.DataItem, DataRowView).Row("FixedMachine").ToString()
e.Row.Cells(8).Controls.Add(FixedMachine)
FixedMachine.Width = 50
Dim chkSel As New CheckBox
chkSel.ID = "Move"
chkSel.Checked = False
e.Row.Cells(0).Controls.Add(chkSel)
Dim row As GridViewRow = TryCast(FixedMachine.NamingContainer, GridViewRow)
strFix = TryCast(row.FindControl("FixedMachine"), Label).Text
If String.IsNullOrEmpty(strFix) Then
chkSel.Enabled = True
Else
chkSel.Enabled = True
' chkSel.Enabled = False
End If
' AddGrdColumn("AvailableTime", "Available Time", "Lable")
'getsum
strGrpMC = TON.Text & MachineNo.Text
For i As Integer = 0 To iLoopMonth - 1
Dim ShpOrd As New Label()
Dim ShpOrdBckOrd As New TextBox()
Dim PlanM1 As New TextBox()
Dim ActualM1 As New TextBox()
Dim BackOrder As New Label()
Dim NeedHr As New Label()
ShpOrd.ID = "ShpOrd"
ShpOrd.Text = TryCast(e.Row.DataItem, DataRowView).Row(arrayMonth(i)).ToString()
e.Row.Cells(11 + (9 * i) + i).Controls.Add(ShpOrd)
ShpOrd.Width = 50
ShpOrdBckOrd.ID = "ShpOrdBckOrd"
ShpOrdBckOrd.Text = ShpOrd.Text
e.Row.Cells(12 + (9 * i) + i).Controls.Add(ShpOrdBckOrd)
ShpOrdBckOrd.Width = 50
PlanM1.ID = "PlanM1"
PlanM1.Text = ""
e.Row.Cells(13 + (9 * i) + i).Controls.Add(PlanM1)
PlanM1.Width = 50
ActualM1.ID = "ActualM1"
ActualM1.Text = ""
ActualM1.AutoPostBack = True
AddHandler ActualM1.TextChanged, AddressOf txtAcutal_TextChanged
e.Row.Cells(14 + (9 * i) + i).Controls.Add(ActualM1)
ActualM1.Width = 50
BackOrder.ID = "BackOrder"
BackOrder.Text = ""
BackOrder.Text = GetBackOrder(ShpOrdBckOrd.Text, ActualM1.Text)
e.Row.Cells(15 + (9 * i) + i).Controls.Add(BackOrder)
BackOrder.Width = 50
NeedHr.ID = "NeedHr"
NeedHr.Text = GetNeedHr(ShpOrd.Text, PlanM1.Text, ST.Text, TRP.Text)
e.Row.Cells(16 + (9 * i) + i).Controls.Add(NeedHr)
NeedHr.Width = 50
' summary
' MsgBox("strGrpMC : " & strGrpMC)
' MsgBox("strTmpGrpMC : " & strTmpGrpMC)
strGrpMC = TON.Text & "-" & MachineNo.Text
If strGrpMC <> strTmpGrpMC Then
LodTmeTT = 0
BalTmeTT = 0
strTmpGrpMC = strGrpMC
strGrpMC = TON.Text & "-" & MachineNo.Text
LodTmeTT = LodTmeTT + Convert.ToDouble(ChkNull(GetNeedHr(ShpOrd.Text, PlanM1.Text, ST.Text, TRP.Text), 0))
Else
strTmpGrpMC = strGrpMC
strGrpMC = TON.Text & "-" & MachineNo.Text
LodTmeTT = LodTmeTT + Convert.ToDouble(ChkNull(GetNeedHr(ShpOrd.Text, PlanM1.Text, ST.Text, TRP.Text), 0))
End If
'("#,##0.00")
Dim AvailableTime As New TextBox()
AvailableTime.ID = "AvailableTime"
AvailableTime.Text = TryCast(e.Row.DataItem, DataRowView).Row("AvailableTime").ToString()
e.Row.Cells(18 + (9 * i) + i).Controls.Add(AvailableTime)
AvailableTime.Width = 50
Dim Loading As New Label()
Loading.ID = "Loading"
Loading.Text = LodTmeTT
e.Row.Cells(17 + (9 * i) + i).Controls.Add(Loading)
Loading.Width = 50
Loading.Text = LodTmeTT
Dim balTme As New Label()
balTme.ID = "balTme"
balTme.Text = GetBalTime(AvailableTime.Text, Loading.Text)
e.Row.Cells(19 + (9 * i) + i).Controls.Add(balTme)
balTme.Width = 50
Dim RatioTme As New Label()
RatioTme.ID = "RatioTme"
RatioTme.Text = GetLoadRatioTime(Loading.Text, AvailableTime.Text)
e.Row.Cells(20 + (9 * i) + i).Controls.Add(RatioTme)
RatioTme.Width = 50
Next
End If
End Sub
添加值的Java代码
<subDataset name="TableDataSet" uuid="c661db1a-6eb7-45f7-9b83-60d1e897aa6e">
<queryString>
<![CDATA[]]>
</queryString>
<field name="parts" class="java.util.List">
<fieldDescription><![CDATA[parts]]></fieldDescription>
</field>
<field name="width" class="java.lang.Double">
<fieldDescription><![CDATA[width]]></fieldDescription>
</field>
<field name="length" class="java.lang.Double">
<fieldDescription><![CDATA[length]]></fieldDescription>
</field>
</subDataset>
<componentElement>
<reportElement x="213" y="289" width="140" height="60" uuid="d189551d-deb4-4dd2-8124-7d6f98fa8a5f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.grid.JSSGridBagLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="Parts Table"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="TableDataSet" uuid="d2e7599c-305c-462e-b6ed-a41a271e055f">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="40" uuid="a0e059cc-643c-4015-a824-c6612add40cf">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="f0b3d3da-0e18-4873-83d6-7b88bb183a10"/>
<text><![CDATA[Parts]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="af940dbe-df85-4655-83c3-50c57b2108a1"/>
<textFieldExpression><![CDATA[$F{parts}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="60" uuid="cc40141d-88d3-40f7-8170-ca977bf9290b">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="60" height="30" uuid="fbd64c97-d94c-4708-afc9-87a49ae1329f"/>
<text><![CDATA[Length]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="60" height="30" uuid="4ecc0959-fd6d-4e78-8987-c83c754edff4"/>
<textFieldExpression><![CDATA[$F{length}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="40" uuid="5dc3cf98-b681-4e63-88c1-38bd8f089e04">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="40" height="30" uuid="346fa23f-c442-4800-967c-741b2303c13e"/>
<text><![CDATA[Width]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="40" height="30" uuid="beee575e-17c4-402e-8246-68e2ccbc43f5"/>
<textFieldExpression><![CDATA[$F{width}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
我在SO here和this one上发布了一些帖子,但没有任何效果。编译jrxml文件后,我可以在Jaspersoft Studio的预览部分看到该表,但在生成报告时却看不到。
有什么帮助吗?
答案 0 :(得分:3)
这可能由于几个原因而发生。例如:
&#34;没有细节&#34;听起来有点疯狂,但这个报告配置也可以做到这一点
您需要将字段集合传递给报告
ArrayList<YourReportObject> reportData = new ArrayList<>();
reportData.add(new YourReportObject());
从集合
创建JRDataSource
JRDataSource dataSource = new JRBeanCollectionDataSource(reportData);
使用dataSource作为参数填充报告
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);
确保YourReportObject
包含所有$F{...}
字段。变量名必须相等!
以下是一些示例:http://jasperreports.sourceforge.net/sample.reference/datasource/
答案 1 :(得分:0)
关注此post后解决了我的问题。我忘了在 jr:table 组件传递数据源。
jrxml 中的更正:
<subDataset name="Dataset1">
<queryString>
<![CDATA[]]>
</queryString>
<field name="part" class="java.lang.String">
<fieldDescription><![CDATA[part]]></fieldDescription>
</field>
<field name="length" class="java.lang.Double">
<fieldDescription><![CDATA[length]]></fieldDescription>
</field>
<field name="width" class="java.lang.Double">
<fieldDescription><![CDATA[width]]></fieldDescription>
</field>
</subDataset>
在 jr:table 标记中添加数据源表达式,如下所示:
<datasetRun subDataset="Dataset1">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{parts})]]></dataSourceExpression>
</datasetRun>
这对我有用。