iReport制作报表

说明1:如何通过iReport编辑预览报表

 

In this tutorial we will see how configuring iReports and how to create, compile and preview a simple report with Jasperreports and the IReportCompiler class

Step1: 配置iReport
1) Select the menu Database->classpath...
2) Complete Microsoft JVM classpath to your JDBC drivers
3) Complete Java VM classpath to your JDBC drivers, tools.jar and jar files of JasperReports:
   X:/path/to/jasperreports-0.4.2-project/JasperReports/lib/commons-beanutils.jar
   X:/path/to/jasperreports-0.4.2-project/JasperReports/lib/commons-collections.jar
   X:/path/to/jasperreports-0.4.2-project/JasperReports/lib/commons-digester.jar
   X:/path/to/jasperreports-0.4.2-project/JasperReports/lib/itext-0.92.jar
   X:/path/to/jasperreports-0.4.2-project/JasperReports/lib/jasperreports.jar
   X:/path/to/jasperreports-0.4.2-project/JasperReports/lib/xerces.jar
4) Set java home (iReport search for installed JDK exploring the windows registry)




Step2: the first report (no database connection required)
1) Create a new report named "mydoc"
2) Add a static text element to the title band
   Pay ever attention to the band linked to your elements !!!
3) Modify the size of font (-->*"FOR EXAMPLE, IF YOU WANT SET SIZE=30*<--) (if it not change, click on font name field and press the tab key... ;-)
4) Align the text to center and modify it
5) Save in a file named mydoc.xml







Step3: it's time to compiling
1) Select menu edit->compile...
2) Check the XML file name
3) Press the "compile" button
4) If all worked correctly, without error, you have successfully compiled your first document using iReport







Now, you are ready to compiling JasperReports samples

Tutorial Two: working with queries...

In this tutorial we will see how to connect to a database, execute a query, retrive fields information and grouping rows with a group band.
For "detailed" information about how to configuring iReport for enabling database connections (you must simply setup the classpath to find JDBC driver classes), see the tutorial
"Tutorial 1: How to compile and preview reports from iReport".

Step1: create a connection
1) Select menu Database->connections
2) Press "new" button to create a new connection
3) Fill for and test your new connection
 nbsp;nbsp; In this tutorial we will use MySQL as DB, but the logic is the same for any database
4) Press "Save". Your new connection will appare in the connections list
5) Close the connections window








Step2: read query fields
1) Create a new report named "tutorial2"
2) Add a static text element to the title band
   Pay ever attention to the band linked to your elements !!!
3) Save in a file named tutorial2.xml
4) Select menu Database->Report query
5) From connections combobox select myconnection
6) Write a selection query. In this tutorial we will select all records of table COMUNI (cities)
   SELECT * FROM COMUNI ORDER BY PROVINCIA, COMUNE
7) Press button labeled "read fields", a new window will appare. Pleas wait... at the end the fields selected by the query will be inserted in the fields listview
8) Press button "Register fields to report" for save fields definition
9) Press button "Save to report" for attach query to report








Step3: create a group
1) Open variables window. You would have to see the list of the fields
2) Select menu view->groups
3) Create a new group (pressing the "new" button) named "Group1"
4) Check the box "Start on a new column"
5) Insert the group expression. In this tutorial we want see all cities grouped by province
   The expression value is: $F{PROVINCIA} 6) Press "OK" to close group definition window, and "close" to close groups list window
7) You will see the new group drawed on your document







Step4: drag and drop...
1) Reopen variables window. You would have to see the list of the fields
2) Drag the field selected for grouping (in my case PROVICIA) on the Group1 band...and drop. A new Field Element will be created
3) Drag another field on detail band
4) I have added at this point two lines, one linked with Group1Header band, and one linked with detail band.
5) Open the ReportProperties (view->report properties) and set num columns=2, columns width=250, spacing=35







Step5: Compilation and preview...
1) Open the compilator (edit->compile...)
2) Select your connection (for me is "myconnection")
3) Press "compile" button





Tutorial Three: How to use a database like MS Access via ODBC bridge with iReport 0.0.6
Please note that form iReport 0.0.8 this "trick" is no more useful and all JDBC access are maded using pure java.

In this tutorial we will see how to configure iReports for use a ODBC driver.
Microsoft JVM is not compatible with java.sun.jdbc.odbcBridge class (One of the many debatable defects of the Microsoft java implementation). For this reason, the use of a ODBC driver is a bit complex in iReport. As we will see, the adopted solution will be the creation of two database connections, one Microsoft compatible and one Java "Sun" compatible. We will use the first inside of iReport, the second out iReport ( for compilation and preview).

Step1: creation of connections
1) Create an ODBC connection (i.e. an Microsoft Access System Data Source Name named "TEST_iReport")
2) Open iReport and select database->connections menu
4) Create two connection with follow parameters...

First connection (For use with Microsoft JVM):
Name = MS ODBC TEST
JDBC driver = com.ms.jdbc.odbc.JdbcOdbcDriver
JDBC URL = jdbc:odbc:TEST_iReport
USER = administrator

Second connection (For use with Sun JVM):
Name = SUN ODBC TEST
JDBC driver = sun.jdbc.odbc.JdbcOdbcDriver
JDBC URL = jdbc:odbc:TEST_iReport
USER = administrator











Step2: create the report (using iReport wizard)
1) Select File->Report wizard menu
2) Select MS ODBC TEST connection and write a select query for a table in the database
3) Click next and select preferred fields
4) Click next at step 3 of the wizard
5) Select a tabular report, i.e. the classic template and press 'next' button
6) Press the next button for finish report wizard. We have now a report for the selected table
7) Save the report









Step3: it's time to compiling
1) Select Tools->IReportCompiler menu
2) Check the XML file name
3) elect SUN ODBC TEST connection
3) Press the "compile" button
4) If all work correctly, without error, you have successfully compiled your report using an ODBC database connection













JasperReports supported tags (updated to iReport 0.3.1 and Jasperreports 0.5.3)

jasperReportnameyes
columnCountyes
printOrderyes
pageWidthyes
pageHeightyes
orientationyes
whenNoDataTypeyes
columnWidthyes
columnSpacingyes
leftMarginyes
rightMarginyes
topMarginyes
bottomMarginyes
isTitleNewPageyes
isSummaryNewPageyes
scriptletClassyes
reportFontnameyes
fontNameyes
sizeyes
isBoldyes
isItalicyes
isUnderlineyes
isStrikeThroughyes
pdfFontNameyes
pdfEncodingyes
isPdfEmbeddedyes
isDefaultyes
parameternameyes
classyes
isForPromptingyes
parameterDescription yes
defaultValueExpression yes
propertynameyes
valueyes
queryString yes
fieldnameyes
classyes
fieldDescription yes
variablenameyes
classyes
resetTypeyes
resetGroupyes
calculationyes
incrementerFactoryClassyes
variableExpression yes
initialValueExpression yes
groupnameyes
isStartNewColumnyes
isStartNewPageyes
isResetPageNumberyes
isReprintHeaderOnEachPageyes
minHeightToStartNewPageyes
groupExpression yes
groupHeader yes
groupFooter yes
background yes
title yes
pageHeader yes
columnHeader yes
detail yes
columnFooter yes
pageFooter yes
summary yes
bandheightyes
linedirectionyes
reportElementpositionTypeyes
isPrintRepeatedValuesyes
modeyes
xyes
yyes
widthyes
heightyes
isRemoveLineWhenBlankyes
isPrintInFirstWholeBandyes
isPrintWhenDetailOverflowsyes
printWhenGroupChangesyes
forecoloryes
backcoloryes
printWhenExpression yes
graphicElementstretchTypeyes
penyes
fillyes
rectangleradiusyes
ellipse yes
imagescaleImageyes
isUsingCacheyes
hAlignyes
vAlignyes
evaluationTimeyes
evaluationGroupyes
hyperlinkTypeyes
imageExpressionclassyes
anchorNameExpression yes
hyperlinkReferenceExpression yes
hyperlinkAnchorExpression yes
hyperlinkPageExpression yes
staticText yes
textElementtextAlignmentyes
verticalAlignmentyes
lineSpacingyes
rotationyes
isStyledTextyes
fontreportFontyes
fontNameyes
sizeyes
isBoldyes
isItalicyes
isUnderlineyes
isStrikeThroughyes
pdfFontNameyes
pdfEncodingyes
isPdfEmbeddedyes
text yes
textFieldisStretchWithOverflowyes
evaluationTimeyes
evaluationGroupyes
patternyes
isBlankWhenNullyes
hyperlinkTypeyes
textFieldExpressionclassyes
subreportisUsingCacheyes
parametersMapExpression yes
subreportParameternameyes
subreportParameterExpression yes
connectionExpression yes
dataSourceExpression yes
subreportExpressionclassyes
elementGroup no


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值