如何在 jasper 报告中添加按钮?
How can I add a button in jasper report?
是否可以在报告中添加一个按钮,任何操作都会被修复?
示例:按钮"View",将显示更详细的统计信息。
评论:
我不太明白如何制作文本元素的按钮
要创建一个 按钮,请创建一个带有 hyperlinkType="Reference"
的 textField
和一个 hyperlinkReferenceExpression
例子
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="JddButton" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a88eaae-fbef-4a3d-b8bf-0b12bafc985b">
<title>
<band height="80" splitType="Stretch">
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement mode="Opaque" x="150" y="20" width="200" height="40" forecolor="#FFFFFF" backcolor="#009900" uuid="822deecb-059b-4921-bfb7-07ee7cbde26a">
<property name="net.sf.jasperreports.export.html.class" value="btn"/>
<property name="net.sf.jasperreports.export.html.id" value="idBtn"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="24"/>
</textElement>
<textFieldExpression><![CDATA["VIEW"]]></textFieldExpression>
<anchorNameExpression><![CDATA["myButton"]]></anchorNameExpression>
<hyperlinkReferenceExpression><![CDATA["https://whosebug.com/users/5292302/petter-friberg"]]></hyperlinkReferenceExpression>
<hyperlinkTooltipExpression><![CDATA["Click to view"]]></hyperlinkTooltipExpression>
</textField>
</band>
</title>
</jasperReport>
会生成
当点击它时,它会将您引导至 hyperlinkReferenceExpression
的值,例如我还设置了 hyperlinkTarget="Blank"
,因此它会在新页面中打开。
有关属性的更多信息,请参阅 JRHyperLink API
嘿,我想让我的按钮在经过它时改变颜色....
没问题,(只要导出是 html,在 pdf 中你需要用注释做一些技巧,但我会忽略它..)。
我在 textElement
上添加了一些 css 标签,参见 reportElement
下的 属性
那么简单css.
<style type="text/css">
a {text-decoration: none}
td.btn:hover {
background-color: yellow !Important;
}
</style>
最后,如何将这个 css 放入输出文件?
Export custom HTML template
是否可以在报告中添加一个按钮,任何操作都会被修复?
示例:按钮"View",将显示更详细的统计信息。
评论:
我不太明白如何制作文本元素的按钮
要创建一个 按钮,请创建一个带有 hyperlinkType="Reference"
的 textField
和一个 hyperlinkReferenceExpression
例子
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="JddButton" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2a88eaae-fbef-4a3d-b8bf-0b12bafc985b">
<title>
<band height="80" splitType="Stretch">
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement mode="Opaque" x="150" y="20" width="200" height="40" forecolor="#FFFFFF" backcolor="#009900" uuid="822deecb-059b-4921-bfb7-07ee7cbde26a">
<property name="net.sf.jasperreports.export.html.class" value="btn"/>
<property name="net.sf.jasperreports.export.html.id" value="idBtn"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="24"/>
</textElement>
<textFieldExpression><![CDATA["VIEW"]]></textFieldExpression>
<anchorNameExpression><![CDATA["myButton"]]></anchorNameExpression>
<hyperlinkReferenceExpression><![CDATA["https://whosebug.com/users/5292302/petter-friberg"]]></hyperlinkReferenceExpression>
<hyperlinkTooltipExpression><![CDATA["Click to view"]]></hyperlinkTooltipExpression>
</textField>
</band>
</title>
</jasperReport>
会生成
当点击它时,它会将您引导至 hyperlinkReferenceExpression
的值,例如我还设置了 hyperlinkTarget="Blank"
,因此它会在新页面中打开。
有关属性的更多信息,请参阅 JRHyperLink API
嘿,我想让我的按钮在经过它时改变颜色....
没问题,(只要导出是 html,在 pdf 中你需要用注释做一些技巧,但我会忽略它..)。
我在 textElement
上添加了一些 css 标签,参见 reportElement
那么简单css.
<style type="text/css">
a {text-decoration: none}
td.btn:hover {
background-color: yellow !Important;
}
</style>
最后,如何将这个 css 放入输出文件?
Export custom HTML template