您的位置:首页 > 其它

iReport制作报表

2004-12-03 10:27 741 查看
说明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).

[b]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

4000

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)
[/b]
jasperReport
name
yes

columnCount
yes

printOrder
yes

pageWidth
yes

pageHeight
yes

orientation
yes

whenNoDataType
yes

columnWidth
yes

columnSpacing
yes

leftMargin
yes

rightMargin
yes

topMargin
yes

bottomMargin
yes

isTitleNewPage
yes

isSummaryNewPage
yes

scriptletClass
yes
reportFont
name
yes

fontName
yes

size
yes

isBold
yes

isItalic
yes

isUnderline
yes

isStrikeThrough
yes

pdfFontName
yes

pdfEncoding
yes

isPdfEmbedded
yes

isDefault
yes
parameter
name
yes

class
yes

isForPrompting
yes
parameterDescription
 
yes
defaultValueExpression
 
yes
property
name
yes

value
yes
queryString
 
yes
field
name
yes

class
yes
fieldDescription
 
yes
variable
name
yes

class
yes

resetType
yes

resetGroup
yes

calculation
yes

incrementerFactoryClass
yes
variableExpression
 
yes
initialValueExpression
 
yes
group
name
yes

isStartNewColumn
yes

isStartNewPage
yes

isResetPageNumber
yes

isReprintHeaderOnEachPage
yes

minHeightToStartNewPage
yes
groupExpression
 
yes
groupHeader
 
yes
groupFooter
 
yes
background
 
yes
title
 
yes
pageHeader
 
yes
columnHeader
 
yes
detail
 
yes
columnFooter
 
yes
pageFooter
 
yes
summary
 
yes
band
height
yes
line
direction
yes
reportElement
positionType
yes

isPrintRepeatedValues
yes

mode
yes

x
yes

y
yes

width
yes

height
yes

isRemoveLineWhenBlank
yes

isPrintInFirstWholeBand
yes

isPrintWhenDetailOverflows
yes

printWhenGroupChanges
yes

forecolor
yes

backcolor
yes
printWhenExpression
 
yes
graphicElement
stretchType
yes

pen
yes

fill
yes
rectangle
radius
yes
ellipse
 
yes
image
scaleImage
yes

isUsingCache
yes

hAlign
yes

vAlign
yes

evaluationTime
yes

evaluationGroup
yes

hyperlinkType
yes
imageExpression
class
yes
anchorNameExpression
 
yes
hyperlinkReferenceExpression
 
yes
hyperlinkAnchorExpression
 
yes
hyperlinkPageExpression
 
yes
staticText
 
yes
textElement
textAlignment
yes

verticalAlignment
yes

lineSpacing
yes

rotation
yes

isStyledText
yes
font
reportFont
yes

fontName
yes

size
yes

isBold
yes

isItalic
yes

isUnderline
yes

isStrikeThrough
yes

pdfFontName
yes

pdfEncoding
yes

isPdfEmbedded
yes
text
 
yes
textField
isStretchWithOverflow
yes

evaluationTime
yes

evaluationGroup
yes

pattern
yes

isBlankWhenNull
yes

hyperlinkType
yes
textFieldExpression
class
yes
subreport
isUsingCache
yes
parametersMapExpression
 
yes
subreportParameter
name
yes
subreportParameterExpression
 
yes
connectionExpression
 
yes
dataSourceExpression
 
yes
subreportExpression
class
yes
elementGroup
 
no

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息