﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Tom-随笔-随笔分类-报表工具</title><link>http://www.blogjava.net/43880800/category/17827.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 03:44:51 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 03:44:51 GMT</pubDate><ttl>60</ttl><item><title>JAVA操作excel</title><link>http://www.blogjava.net/43880800/archive/2006/12/19/88798.html</link><dc:creator>Tom</dc:creator><author>Tom</author><pubDate>Tue, 19 Dec 2006 07:00:00 GMT</pubDate><guid>http://www.blogjava.net/43880800/archive/2006/12/19/88798.html</guid><wfw:comment>http://www.blogjava.net/43880800/comments/88798.html</wfw:comment><comments>http://www.blogjava.net/43880800/archive/2006/12/19/88798.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/43880800/comments/commentRss/88798.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/43880800/services/trackbacks/88798.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 97.44%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; HEIGHT: 1160px; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> com.eesys.apps.logic;<br /></span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.File;<br /></span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.FileInputStream;<br /></span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.InputStream;<br /></span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 7</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> jxl.Cell;<br /></span>
				<span style="COLOR: #008080"> 8</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> jxl.CellType;<br /></span>
				<span style="COLOR: #008080"> 9</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> jxl.Sheet;<br /></span>
				<span style="COLOR: #008080">10</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> jxl.Workbook;<br /></span>
				<span style="COLOR: #008080">11</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> jxl.write.Label;<br /></span>
				<span style="COLOR: #008080">12</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080">13</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_241_1830_Open_Image" onclick="this.style.display='none'; Codehighlighter1_241_1830_Open_Text.style.display='none'; Codehighlighter1_241_1830_Closed_Image.style.display='inline'; Codehighlighter1_241_1830_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_241_1830_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_241_1830_Closed_Text.style.display='none'; Codehighlighter1_241_1830_Open_Image.style.display='inline'; Codehighlighter1_241_1830_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> PrintManager </span>
				<span id="Codehighlighter1_241_1830_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.blogjava.net/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_241_1830_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080">14</span>
						<span style="COLOR: #000000">
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    <br /></span>
						<span style="COLOR: #008080">15</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_287_1827_Open_Image" onclick="this.style.display='none'; Codehighlighter1_287_1827_Open_Text.style.display='none'; Codehighlighter1_287_1827_Closed_Image.style.display='inline'; Codehighlighter1_287_1827_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_287_1827_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_287_1827_Closed_Text.style.display='none'; Codehighlighter1_287_1827_Open_Image.style.display='inline'; Codehighlighter1_287_1827_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />      </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">static</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> main(String[] args) </span>
						<span id="Codehighlighter1_287_1827_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.blogjava.net/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_287_1827_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">16</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        jxl.Workbook rwb </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">null</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080">17</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_327_1696_Open_Image" onclick="this.style.display='none'; Codehighlighter1_327_1696_Open_Text.style.display='none'; Codehighlighter1_327_1696_Closed_Image.style.display='inline'; Codehighlighter1_327_1696_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_327_1696_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_327_1696_Closed_Text.style.display='none'; Codehighlighter1_327_1696_Open_Image.style.display='inline'; Codehighlighter1_327_1696_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">try</span>
								<span id="Codehighlighter1_327_1696_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_327_1696_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">18</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">构建Workbook对象, 只读Workbook对象<br /></span>
										<span style="COLOR: #008080">19</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">直接从本地文件创建Workbook<br /></span>
										<span style="COLOR: #008080">20</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">从输入流创建Workbook</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">21</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">            System.out.println(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">********START!*******</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">22</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          InputStream is </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> FileInputStream(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">D:/test.xls</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">23</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          rwb </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> Workbook.getWorkbook(is);<br /></span>
										<span style="COLOR: #008080">24</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">25</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">Sheet(术语：工作表)就是Excel表格左下角的Sheet1,Sheet2,Sheet3但在程序中<br /></span>
										<span style="COLOR: #008080">26</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">Sheet的下标是从0开始<br /></span>
										<span style="COLOR: #008080">27</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获取第一张Sheet表</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">28</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           Sheet rs </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> rwb.getSheet(</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">29</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获取Sheet表中所包含的总列数</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">30</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> rsColumns </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> rs.getColumns();<br /></span>
										<span style="COLOR: #008080">31</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获取Sheet表中所包含的总行数</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">32</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           </span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> rsRows </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> rs.getRows();<br /></span>
										<span style="COLOR: #008080">33</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获取指定单元格的对象引用</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">34</span>
										<span style="COLOR: #008000">
												<img id="Codehighlighter1_894_1083_Open_Image" onclick="this.style.display='none'; Codehighlighter1_894_1083_Open_Text.style.display='none'; Codehighlighter1_894_1083_Closed_Image.style.display='inline'; Codehighlighter1_894_1083_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_894_1083_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_894_1083_Closed_Text.style.display='none'; Codehighlighter1_894_1083_Open_Image.style.display='inline'; Codehighlighter1_894_1083_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           </span>
										<span style="COLOR: #0000ff">for</span>
										<span style="COLOR: #000000">(</span>
										<span style="COLOR: #0000ff">int</span>
										<span style="COLOR: #000000"> i</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">;i</span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000">rsRows;i</span>
										<span style="COLOR: #000000">++</span>
										<span style="COLOR: #000000">)</span>
										<span id="Codehighlighter1_894_1083_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.blogjava.net/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_894_1083_Open_Text">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">35</span>
												<span style="COLOR: #000000">
														<img id="Codehighlighter1_934_1041_Open_Image" onclick="this.style.display='none'; Codehighlighter1_934_1041_Open_Text.style.display='none'; Codehighlighter1_934_1041_Closed_Image.style.display='inline'; Codehighlighter1_934_1041_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
														<img id="Codehighlighter1_934_1041_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_934_1041_Closed_Text.style.display='none'; Codehighlighter1_934_1041_Open_Image.style.display='inline'; Codehighlighter1_934_1041_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />             </span>
												<span style="COLOR: #0000ff">for</span>
												<span style="COLOR: #000000">(</span>
												<span style="COLOR: #0000ff">int</span>
												<span style="COLOR: #000000"> j</span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000">0</span>
												<span style="COLOR: #000000">;j</span>
												<span style="COLOR: #000000">&lt;</span>
												<span style="COLOR: #000000">rsColumns;j</span>
												<span style="COLOR: #000000">++</span>
												<span style="COLOR: #000000">)</span>
												<span id="Codehighlighter1_934_1041_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.blogjava.net/images/dot.gif" />
												</span>
												<span id="Codehighlighter1_934_1041_Open_Text">
														<span style="COLOR: #000000">{<br /></span>
														<span style="COLOR: #008080">36</span>
														<span style="COLOR: #000000">
																<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />               Cell cell </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> rs.getCell(j,i);<br /></span>
														<span style="COLOR: #008080">37</span>
														<span style="COLOR: #000000">
																<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />               System.out.print(cell.getContents()</span>
														<span style="COLOR: #000000">+</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">);<br /></span>
														<span style="COLOR: #008080">38</span>
														<span style="COLOR: #000000">
																<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />             }</span>
												</span>
												<span style="COLOR: #000000">
														<br />
												</span>
												<span style="COLOR: #008080">39</span>
												<span style="COLOR: #000000">
														<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />             System.out.println();<br /></span>
												<span style="COLOR: #008080">40</span>
												<span style="COLOR: #000000">
														<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />           }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
										</span>
										<span style="COLOR: #008080">41</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">利用已经创建的Excel工作薄创建新的可写入的Excel工作薄</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">42</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           jxl.write.WritableWorkbook wwb </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> Workbook.createWorkbook(</span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> File(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">D:/Book2.xls</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">),rwb);<br /></span>
										<span style="COLOR: #008080">43</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">读取第一张工作表</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">44</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           <br /></span>
										<span style="COLOR: #008080">45</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           jxl.write.WritableSheet ws </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> wwb.getSheet(</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">46</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           <br /></span>
										<span style="COLOR: #008080">47</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           <br /></span>
										<span style="COLOR: #008080">48</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">获得第一个单元格对象</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">49</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           jxl.write.WritableCell wc </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> ws.getWritableCell(</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">50</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">判断单元格的类型, 做出相应的转化</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">51</span>
										<span style="COLOR: #008000">
												<img id="Codehighlighter1_1478_1575_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1478_1575_Open_Text.style.display='none'; Codehighlighter1_1478_1575_Closed_Image.style.display='inline'; Codehighlighter1_1478_1575_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_1478_1575_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1478_1575_Closed_Text.style.display='none'; Codehighlighter1_1478_1575_Open_Image.style.display='inline'; Codehighlighter1_1478_1575_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (wc.getType() </span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> CellType.LABEL) </span>
										<span id="Codehighlighter1_1478_1575_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.blogjava.net/images/dot.gif" />
										</span>
										<span id="Codehighlighter1_1478_1575_Open_Text">
												<span style="COLOR: #000000">{<br /></span>
												<span style="COLOR: #008080">52</span>
												<span style="COLOR: #000000">
														<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />             Label l </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> (Label) wc;<br /></span>
												<span style="COLOR: #008080">53</span>
												<span style="COLOR: #000000">
														<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />             l.setString(</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">The value has been modified.</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">);<br /></span>
												<span style="COLOR: #008080">54</span>
												<span style="COLOR: #000000">
														<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />           }</span>
										</span>
										<span style="COLOR: #000000">
												<br />
										</span>
										<span style="COLOR: #008080">55</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">写入Excel对象</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">56</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">           wwb.write();<br /></span>
										<span style="COLOR: #008080">57</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           wwb.close();<br /></span>
										<span style="COLOR: #008080">58</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />           System.out.println(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">********END!*******</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">);<br /></span>
										<span style="COLOR: #008080">59</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">60</span>
										<span style="COLOR: #000000">
												<img id="Codehighlighter1_1715_1750_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1715_1750_Open_Text.style.display='none'; Codehighlighter1_1715_1750_Closed_Image.style.display='inline'; Codehighlighter1_1715_1750_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_1715_1750_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1715_1750_Closed_Text.style.display='none'; Codehighlighter1_1715_1750_Open_Image.style.display='inline'; Codehighlighter1_1715_1750_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #0000ff">catch</span>
								<span style="COLOR: #000000">(Exception e)</span>
								<span id="Codehighlighter1_1715_1750_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1715_1750_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">61</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          e.printStackTrace();<br /></span>
										<span style="COLOR: #008080">62</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">63</span>
								<span style="COLOR: #000000">
										<img id="Codehighlighter1_1764_1822_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1764_1822_Open_Text.style.display='none'; Codehighlighter1_1764_1822_Closed_Image.style.display='inline'; Codehighlighter1_1764_1822_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_1764_1822_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1764_1822_Closed_Text.style.display='none'; Codehighlighter1_1764_1822_Open_Image.style.display='inline'; Codehighlighter1_1764_1822_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">finally</span>
								<span id="Codehighlighter1_1764_1822_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_1764_1822_Open_Text">
										<span style="COLOR: #000000">{<br /></span>
										<span style="COLOR: #008080">64</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />          </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">操作完成时，关闭对象，释放占用的内存空间</span>
										<span style="COLOR: #008000">
												<br />
										</span>
										<span style="COLOR: #008080">65</span>
										<span style="COLOR: #008000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
										</span>
										<span style="COLOR: #000000">          rwb.close();<br /></span>
										<span style="COLOR: #008080">66</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
												<br />
										</span>
										<span style="COLOR: #008080">67</span>
										<span style="COLOR: #000000">
												<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
								</span>
								<span style="COLOR: #008080">68</span>
								<span style="COLOR: #000000">
										<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />      }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">69</span>
						<span style="COLOR: #000000">
								<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />    }</span>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">70</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<br />JSP 文件<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080"> 1</span><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000">@ page contentType</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/html; charset=GBK</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">%&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000">@ page </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">java.io.File</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">%&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000">@ page </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">java.io.FileInputStream</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">%&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000">@ page </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">java.io.FileOutputStream</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">%&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000">@ page </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">jxl.write.WritableSheet</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">%&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000">@ page </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">java.io.InputStream</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">%&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">&lt;%</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />response.reset();</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">清除Buffer</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #008000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">response.setContentType(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">application/vnd.ms-excel</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />File fileWrite </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> File(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">d:/test.xls</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />response.setContentLength((</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">) fileWrite.length()); <br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />InputStream in</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileInputStream(fileWrite);<br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] b </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">2048</span><span style="COLOR: #000000">];<br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img id="Codehighlighter1_559_623_Open_Image" onclick="this.style.display='none'; Codehighlighter1_559_623_Open_Text.style.display='none'; Codehighlighter1_559_623_Closed_Image.style.display='inline'; Codehighlighter1_559_623_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_559_623_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_559_623_Closed_Text.style.display='none'; Codehighlighter1_559_623_Open_Image.style.display='inline'; Codehighlighter1_559_623_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> ((len </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> in.read(b)) </span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_559_623_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_559_623_Open_Text"><span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    response.getOutputStream().write(b, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, len); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 向浏览器输出</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #008000"><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /></span><span style="COLOR: #000000">   }</span></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">19</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />in.close();<br /></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />response.getOutputStream().close();<br /></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">%&gt;</span></div><img src ="http://www.blogjava.net/43880800/aggbug/88798.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/43880800/" target="_blank">Tom</a> 2006-12-19 15:00 <a href="http://www.blogjava.net/43880800/archive/2006/12/19/88798.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>iReport &amp; JasperReport配置及用户简明手册</title><link>http://www.blogjava.net/43880800/archive/2006/12/04/85434.html</link><dc:creator>Tom</dc:creator><author>Tom</author><pubDate>Mon, 04 Dec 2006 10:28:00 GMT</pubDate><guid>http://www.blogjava.net/43880800/archive/2006/12/04/85434.html</guid><wfw:comment>http://www.blogjava.net/43880800/comments/85434.html</wfw:comment><comments>http://www.blogjava.net/43880800/archive/2006/12/04/85434.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/43880800/comments/commentRss/85434.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/43880800/services/trackbacks/85434.html</trackback:ping><description><![CDATA[
		<h2 class="diaryTitle">iReport &amp; JasperReport配置及用户简明手册- -</h2>
		<p>                                       </p>
		<p>
		</p>
		<p>关于iReport和JasperReport的简明手册</p>
		<p>By Gem 伍子轩</p>
		<br />
		<font size="+0">
				<font size="+0">
						<p>
								<strong>
								</strong>
						</p>
						<h1>
								<font size="+0">1</font>安装</h1>
						<h2>
								<font size="+0">1.1 iReport</font>的安装</h2>
						<font size="+0">iReport</font>直接解压后，将<font size="+0">J2SDK\lib</font>目录下的<font size="+0">tools.jar</font>拷贝到<font size="+0">iReport\lib</font>目录下，然后在<font size="+0">iReport</font>目录下运行<font size="+0">iReport.bat</font>即可。<br />需要注意的是<font size="+0">tools.jar</font>的版本必须要与本机安装的<font size="+0">jre</font>一致，也就是说，如果系统安装的是<font size="+0">jre1.4.2</font>就必须用<font size="+0">jdk1.4.2</font>的<font size="+0">tools.jar</font>。<br /><h2><font size="+0">1.2 JapserReport</font>开发（运行）环境的搭建</h2><p><font size="+0">JasperReport</font>的开发环境必须要导入以下所有包：</p><p><font size="+0">1．  JasperReport</font>包，如<font size="+0">jasperreports-0.6.1.jar</font>；</p><p><font size="+0">2．  Aparche Common</font>包，包括<font size="+0">logging</font>、<font size="+0">digester</font>、<font size="+0">beanutils</font>、<font size="+0">collections</font>、<font size="+0">logging-api</font>；</p><p><font size="+0">3．  iText</font>包，包括<font size="+0">itext-1.1.jar</font>和<font size="+0">iTextAsian.jar</font>（用于输出中文字符到<font size="+0">PDF</font>文件）</p><p>以上所有包（除了<font size="+0">iTextAsian.jar</font>）都已经包含在<font size="+0">iReport\lib</font>目录下。</p><font size="+0"><font size="+0"><h1><font size="+0">2 </font>开发流程</h1><p>用<font size="+0">iReport</font>可视化编辑生成的文件是<font size="+0">jrxml</font>文档，这是一种<font size="+0">xml</font>文件，记录了一份<font size="+0">report</font>的详细信息，我们可以直接用写字板打开它编辑，<font size="+0">iReport</font>就是一个方便我们生成和编辑<font size="+0">jrxml</font>文件的工具，它也可以很方便地将<font size="+0">jrxml</font>文件编译成<font size="+0">jasper</font>报表文件。</p><p><font size="+0">jrxml</font>文件通过<font size="+0">Jasper</font>编译之后就变成了<font size="+0">jasper</font>文件，这份文件才是真正在程序中调用生成报表的<font size="+0">report</font>文件。</p><p>但是有一点要注意的是，<font size="+0">jasper</font>的各个版本编译出来的<font size="+0">jasper</font>文件并不兼容，就是说用<font size="+0">0.6.1</font>版编译出来的文件用<font size="+0">0.6.4</font>版调用是会出错的，而<font size="+0">iReport</font>自带的<font size="+0">Jasper</font>版本是<font size="+0">0.6.1</font>，而<font size="+0">jasper</font>的最新版本是<font size="+0">0.6.4</font>。所以为了保持通用性，我建议只用<font size="+0">iReport</font>来开发编辑<font size="+0">jrxml</font>文件，而不编译成<font size="+0">jasper</font>文件，在我们的打印报表程序中再即时编译一次。虽然这样效率可能会低了一点，但是保证了不同版本的兼容性。</p><p>在我们的程序中，要调用<font size="+0">Jasper</font>的话，首先要得到一个数据库的<font size="+0">Connection</font>，形如：<font size="+0">Connection con = ...</font></p><p>需要往<font size="+0">JasperReport</font>传参数的话只需要新建一个<font size="+0">Map</font>，以参数名作为<font size="+0">key</font>，需要传入的对象作为<font size="+0">value</font>，譬如：</p><p><font size="+0">Map props = new HashMap();</font></p><p><font size="+0">      props.put("name", new String("name"));</font></p><p>需要多个参数只需分别<font size="+0">put</font>进<font size="+0">Map</font>里去就可以了。</p><font size="+0"><font size="+0"><p><font size="+0">JasperReport</font>有如下几个主要的<font size="+0">Manager</font>：</p><table cellspacing="0" cellpadding="0" border="1"><tbody><tr><td valign="top" width="163"><strong><font size="+0">JasperCompileManager<br /></font></strong></td><td valign="top" width="405"><p>将<font size="+0">jrxml</font>文件编译成<font size="+0">jasper</font>文件或<font size="+0">JasperReport</font>对象</p></td></tr><tr><td valign="top" width="163"><strong><font size="+0">JasperFillManager<br /></font></strong></td><td valign="top" width="405"><p>从数据源中获取数据并填充<font size="+0">jasper</font>文件或<font size="+0">JasperReport</font>对象，产生<font size="+0">JasperPrint</font>对象</p></td></tr><tr><td valign="top" width="163"><strong><font size="+0">JasperPrintManager<br /></font></strong></td><td valign="top" width="405"><p>将<font size="+0">JasperPrint</font>对象直接输出到打印机打印</p></td></tr><tr><td valign="top" width="163"><strong><font size="+0">JasperExportManager<br /></font></strong></td><td valign="top" width="405"><p>将<font size="+0">JasperPrint</font>对象导出成<font size="+0">PDF</font>或<font size="+0">HTML</font>文件（或流）</p></td></tr><tr><td valign="top" width="163"><strong><font size="+0">JasperRunManager<br /></font></strong></td><td valign="top" width="405"><p>运行一个<font size="+0">jasper</font>文件或<font size="+0">JasperReport</font>对象并输出到<font size="+0">PDF</font>或<font size="+0">Html</font>文件（或流）中，我的理解是等于集成了<strong><font size="+0">JasperFillManager</font></strong>和<strong><font size="+0">JasperExportManager</font></strong>的功能</p></td></tr></tbody></table><p>对于上述对象的详细说明请参阅<font size="+0">JasperReport</font>的文档。</p><p>例程：</p>例程： 
<p><font size="+0">public static void main(String[] args) {</font></p><p><font size="+0">    try {</font></p><p><font size="+0">      Class.forName("org.gjt.mm.mysql.Driver");</font></p><p><font size="+0">      Connection con = DriverManager.getConnection(</font></p><p><font size="+0">          "jdbc:mysql://wes:3306/umpdb?useUnicode=true&amp;characterEncoding=GBK", "root", "elite");</font></p><p><font size="+0">      File f1 = new File("Account.jrxml");</font></p><p><font size="+0">      File f2 = new File("Contact.jrxml");</font></p><p><font size="+0">      JasperReport main = JasperCompileManager.compileReport(f1</font></p><p><font size="+0">          .getAbsolutePath());</font></p><p><font size="+0">      JasperReport report = JasperCompileManager.compileReport(f2</font></p><p><font size="+0">          .getAbsolutePath());</font></p><p><font size="+0">      Map props = new HashMap();</font></p><p><font size="+0">      props.put("subreport", report);</font></p><p><font size="+0">      JasperPrint print = JasperFillManager.fillReport(main, props,con);</font></p><p><font size="+0">      //JasperPrintManager.printReport(print,true);</font></p><p><font size="+0">      JasperExportManager.exportReportToPdfFile(print, "a.pdf");</font></p><p><font size="+0">      //JasperRunManager.runReportToPdfFile("Account.jasper", "a.pdf", props, con);</font></p><p><font size="+0">    } catch (ClassNotFoundException e) {</font></p><p><font size="+0">      // TODO </font>自动生成<font size="+0"> catch </font>块</p><p><font size="+0">      e.printStackTrace();</font></p><p><font size="+0">    } catch (SQLException e) {</font></p><p><font size="+0">      // TODO </font>自动生成<font size="+0"> catch </font>块</p><p><font size="+0">      e.printStackTrace();</font></p><p><font size="+0">    } catch (JRException e) {</font></p><p><font size="+0">      // TODO </font>自动生成<font size="+0"> catch </font>块</p><p><font size="+0">      e.printStackTrace();</font></p><p><font size="+0">    }</font></p><p><font size="+0">  }</font></p><font size="+0"><font size="+0"><h1><font size="+0">3 </font>注意事项</h1><p><font size="+0">1</font>．<font size="+0">iReport</font>中新建中文报表的时候记得要输入<font size="+0">XML</font>编码<font size="+0">GB2312</font>。</p><p><font size="+0">2</font>．<font size="+0">iReport</font>中定义中文字体的时候，要选择<font size="+0">PDF Font Name</font>为<font size="+0">STSong-Light</font>（宋体）、<font size="+0">MHei-Medium</font>（黑体）、<font size="+0">MSung-Light</font>，在<font size="+0">PDF Encoding</font>中选择<font size="+0">GB-UCS2-H(Chinese Simplified)</font>，否则输出到<font size="+0">PDF</font>时会乱码。</p><p><font size="+0">3</font>．用<font size="+0">Report SQL</font>查询之后，可能会出现某些字段没有自动建立<font size="+0">Field</font>，就需要在<font size="+0">Field</font>中手动定义了。</p></font></font></font></font></font></font></font>
		</font>
<img src ="http://www.blogjava.net/43880800/aggbug/85434.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/43880800/" target="_blank">Tom</a> 2006-12-04 18:28 <a href="http://www.blogjava.net/43880800/archive/2006/12/04/85434.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jasperreport可以用Collection做为数据源，这种方式比用Connection方式更为灵活方便 </title><link>http://www.blogjava.net/43880800/archive/2006/11/28/84157.html</link><dc:creator>Tom</dc:creator><author>Tom</author><pubDate>Tue, 28 Nov 2006 14:40:00 GMT</pubDate><guid>http://www.blogjava.net/43880800/archive/2006/11/28/84157.html</guid><wfw:comment>http://www.blogjava.net/43880800/comments/84157.html</wfw:comment><comments>http://www.blogjava.net/43880800/archive/2006/11/28/84157.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/43880800/comments/commentRss/84157.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/43880800/services/trackbacks/84157.html</trackback:ping><description><![CDATA[
		<h2> </h2>
		<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
				<div>
						<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page contentType</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">text/html;charset=GBK</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page import</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">dori.jasper.engine.*</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page import</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">java.util.*</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page import</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">java.io.*</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page import</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">java.sql.*</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page import</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">com.zx.report.util.CarUse</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">@ page import</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">dori.jasper.engine.data.*</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">&lt;%</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />Connection conn </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">null</span>
						<span style="COLOR: #000000">; <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />Statement st </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">null</span>
						<span style="COLOR: #000000">; <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />ResultSet rs </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">null</span>
						<span style="COLOR: #000000">; <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" /></span>
						<span style="COLOR: #0000ff">byte</span>
						<span style="COLOR: #000000">[] bytes </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">null</span>
						<span style="COLOR: #000000">; <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />List carUseList</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> ArrayList(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" /><br /><img id="Codehighlighter1_406_2656_Open_Image" onclick="this.style.display='none'; Codehighlighter1_406_2656_Open_Text.style.display='none'; Codehighlighter1_406_2656_Closed_Image.style.display='inline'; Codehighlighter1_406_2656_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><img id="Codehighlighter1_406_2656_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_406_2656_Closed_Text.style.display='none'; Codehighlighter1_406_2656_Open_Image.style.display='inline'; Codehighlighter1_406_2656_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" /></span>
						<span style="COLOR: #0000ff">try</span>
						<span id="Codehighlighter1_406_2656_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" />
						</span>
						<span id="Codehighlighter1_406_2656_Open_Text">
								<span style="COLOR: #000000">{ <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />Class.forName(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">com.microsoft.jdbc.sqlserver.SQLServerDriver</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />conn </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">DriverManager.getConnection(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">jdbc:microsoft:sqlserver://10.10.10.207:1433;DatabaseName=report;user=sa;password=111111</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /></span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">以输入流方式</span>
								<span style="COLOR: #008000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">   InputStream reportFile </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> getClass().getClassLoader().getResourceAsStream(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">carUserBd.jasper</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /></span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">以reportFile方式 <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /></span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">File reportFile =new File(request.getRealPath("/report/carUserBd.jasper"));</span>
								<span style="COLOR: #008000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />Map parameters </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> HashMap(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />String sqlCarUser</span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">SELECT car.carNo, dept.Name , people.peopleName,carUse.useDescription ,</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> carUse.beginTime , carUse.planEndTime , carUse.comment , carUse.driver,</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> carUse.peopleNumber ,OneWay= case carUse.isOneWay  when 0 then '双程'  else '单程'  end, </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">isFirst= case carUse.priority when 0  then '低' when  1  then  '中'  else  '高'  end, carUse.start , </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">carUse.destination , people.peopleName as ratifier FROM DEPT_CARUSELOG carUse , DEPT_CARINFO car , </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">ADMIN_ORGANIZATION dept , PUBLIC_PEOPLEINFO people WHERE carUse.id=290 and </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">caruse.carId=car.carId and carUse.departId=dept.id and carUse.peopleId=people.peopleId</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">; <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />st </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> conn.createStatement(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />rs </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> st.executeQuery(sqlCarUser); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img id="Codehighlighter1_1556_2134_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1556_2134_Open_Text.style.display='none'; Codehighlighter1_1556_2134_Closed_Image.style.display='inline'; Codehighlighter1_1556_2134_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" width="11" align="top" /><img id="Codehighlighter1_1556_2134_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1556_2134_Closed_Text.style.display='none'; Codehighlighter1_1556_2134_Open_Image.style.display='inline'; Codehighlighter1_1556_2134_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif" width="11" align="top" /></span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000">(rs.next())</span>
								<span id="Codehighlighter1_1556_2134_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" />
								</span>
								<span id="Codehighlighter1_1556_2134_Open_Text">
										<span style="COLOR: #000000">{ <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />CarUse carUse</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #0000ff">new</span>
										<span style="COLOR: #000000"> CarUse(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setCarNo(rs.getString(</span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setName(rs.getString(</span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setPeopleName(rs.getString(</span>
										<span style="COLOR: #000000">3</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setUseDescription(rs.getString(</span>
										<span style="COLOR: #000000">4</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setBeginTime(rs.getDate(</span>
										<span style="COLOR: #000000">5</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setPlanEndTime(rs.getDate(</span>
										<span style="COLOR: #000000">6</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setComment(rs.getString(</span>
										<span style="COLOR: #000000">7</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setDriver(rs.getString(</span>
										<span style="COLOR: #000000">8</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setPeopleNumber(rs.getString(</span>
										<span style="COLOR: #000000">9</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setOneWay(rs.getString(</span>
										<span style="COLOR: #000000">10</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setIsFirst(rs.getString(</span>
										<span style="COLOR: #000000">11</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setStart(rs.getString(</span>
										<span style="COLOR: #000000">12</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setDestination(rs.getString(</span>
										<span style="COLOR: #000000">13</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUse.setRatifier(rs.getString(</span>
										<span style="COLOR: #000000">14</span>
										<span style="COLOR: #000000">)); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />carUseList.add(carUse); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" width="11" align="top" />}</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />JRBeanCollectionDataSource ds </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> JRBeanCollectionDataSource(carUseList); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />bytes </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />JasperRunManager.runReportToPdf( <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />reportFile, <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />parameters, <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />ds); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />String fileName </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">test.pdf</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">; <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />response.setContentType(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">application/pdf</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />response.addHeader( <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /></span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">Content-Disposition</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /></span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">attachment;filename=\</span>
								<span style="COLOR: #000000">""</span>
								<span style="COLOR: #000000"> + fileName);</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />
								</span>
								<span style="COLOR: #000000">
										<br />
										<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />response.setContentLength(bytes.length); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />ServletOutputStream ouputStream </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> response.getOutputStream(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />System.</span>
								<span style="COLOR: #0000ff">out</span>
								<span style="COLOR: #000000">.println(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">5</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />ouputStream.write(bytes, </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">, bytes.length); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />ouputStream.flush(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />ouputStream.close(); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img id="Codehighlighter1_2684_2745_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2684_2745_Open_Text.style.display='none'; Codehighlighter1_2684_2745_Closed_Image.style.display='inline'; Codehighlighter1_2684_2745_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><img id="Codehighlighter1_2684_2745_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2684_2745_Closed_Text.style.display='none'; Codehighlighter1_2684_2745_Open_Image.style.display='inline'; Codehighlighter1_2684_2745_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />}</span>
						</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">catch</span>
						<span style="COLOR: #000000"> (SQLException sqle) </span>
						<span id="Codehighlighter1_2684_2745_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" />
						</span>
						<span id="Codehighlighter1_2684_2745_Open_Text">
								<span style="COLOR: #000000">{ <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />System.</span>
								<span style="COLOR: #0000ff">out</span>
								<span style="COLOR: #000000">.println(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">SQLException:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000"> sqle.getMessage()); <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img id="Codehighlighter1_2769_2792_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2769_2792_Open_Text.style.display='none'; Codehighlighter1_2769_2792_Closed_Image.style.display='inline'; Codehighlighter1_2769_2792_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><img id="Codehighlighter1_2769_2792_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2769_2792_Closed_Text.style.display='none'; Codehighlighter1_2769_2792_Open_Image.style.display='inline'; Codehighlighter1_2769_2792_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />}</span>
						</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">catch</span>
						<span style="COLOR: #000000"> (JRException e) </span>
						<span id="Codehighlighter1_2769_2792_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" />
						</span>
						<span id="Codehighlighter1_2769_2792_Open_Text">
								<span style="COLOR: #000000">{ <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" />e.printStackTrace(); <br /><img id="Codehighlighter1_2827_2831_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2827_2831_Open_Text.style.display='none'; Codehighlighter1_2827_2831_Closed_Image.style.display='inline'; Codehighlighter1_2827_2831_Closed_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top" /><img id="Codehighlighter1_2827_2831_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2827_2831_Closed_Text.style.display='none'; Codehighlighter1_2827_2831_Open_Image.style.display='inline'; Codehighlighter1_2827_2831_Open_Text.style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" />}</span>
						</span>
						<span style="COLOR: #0000ff">catch</span>
						<span style="COLOR: #000000">(ClassNotFoundException cnfe)</span>
						<span id="Codehighlighter1_2827_2831_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img height="20" src="http://www.cnblogs.com/Images/dot.gif" width="15" />
						</span>
						<span id="Codehighlighter1_2827_2831_Open_Text">
								<span style="COLOR: #000000">{ <br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif" width="11" align="top" /><br /><img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" width="11" align="top" />}</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />
						</span>
						<span style="COLOR: #000000">%&gt;</span>
						<span style="COLOR: #000000">
								<br />
								<img height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" width="11" align="top" />jasperreport可以用Collection做为数据源，这种方式比用Connection方式更为灵活方便 <br /></span>
				</div>
		</div>
<img src ="http://www.blogjava.net/43880800/aggbug/84157.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/43880800/" target="_blank">Tom</a> 2006-11-28 22:40 <a href="http://www.blogjava.net/43880800/archive/2006/11/28/84157.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ireport+jasperreports 探索</title><link>http://www.blogjava.net/43880800/archive/2006/11/28/84155.html</link><dc:creator>Tom</dc:creator><author>Tom</author><pubDate>Tue, 28 Nov 2006 14:36:00 GMT</pubDate><guid>http://www.blogjava.net/43880800/archive/2006/11/28/84155.html</guid><wfw:comment>http://www.blogjava.net/43880800/comments/84155.html</wfw:comment><comments>http://www.blogjava.net/43880800/archive/2006/11/28/84155.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/43880800/comments/commentRss/84155.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/43880800/services/trackbacks/84155.html</trackback:ping><description><![CDATA[
		<p>
				<font color="#a52a2a">这几天在弄ireport+jasperreports的报表，终于弄得差不多了····<br />下面就把我这几天做的一些东西记录下来····<br />其中提出一些特别要注意的地方（我就是在那几个地方浪费了些时间）···</font>
		</p>
		<p>
				<font color="#a52a2a">1、先介绍一下ireport及asperreports吧····<br />Jasperreport是一个报表制作程序，用户需要按照它制定的规则编写一个XML文件，<br />然后得到用户需要输出的格式文件。它支持输出的文件格式包括PDF,HTML,XML,XLS,CVS等等。<br />而iReport就是一个制作Jasperreport的XML文件的可视化开发工具。</font>
		</p>
		<p>
				<font color="#a52a2a">2、下载ireport和jasperreports···<br />jasperreport下载地址：（我下的是jasperreports-0.6.8）</font>
				<a href="http://jasperreports.sourceforge.net/">
						<font color="#a52a2a">http://jasperreports.sourceforge.net</font>
				</a>
				<br />
				<font color="#a52a2a">ireport下载地址：（我下的是iReport0.5.0）</font>
				<a href="http://ireport.sourceforge.net/">
						<font color="#a52a2a">http://ireport.sourceforge.net</font>
				</a>
		</p>
		<p>
				<font color="#a52a2a">3、下载了ireport将它解压缩以后运行iReport.bat文件，过大约30秒如果能出现ireport的主窗体<br />则表明你的系统已经可以运行ireport了，但是我的不行，所以我编辑目录下的iReport.bat文件，<br />代码如下····<br />@echo off</font>
		</p>
		<p>
				<font color="#a52a2a">set JAVA_HOME=C:\j2sdk1.4.0_03<br />set ANT_HOME=C:\ant<br />set IREPORT_HOME=C:\Documenti\progetti\iReport\iReport2\</font>
		</p>
		<p>
				<font color="#a52a2a">rem %ANT_HOME%\bin\ant javadocs<br />%ANT_HOME%\bin\ant iReport</font>
		</p>
		<p>
				<font color="#a52a2a">----------------<br />这里是采用ant来运行的，所以还需要下载一个ant···<br />如果你没有安装ant的话也可以找到noAnt文件夹下的startup.bat文件即可运行···</font>
		</p>
		<p>
				<font color="#a52a2a">4、数据库···<br />我是用的mysql数据库，之前配置数据库的JDBC驱动器一直不成功原因是我下的mysql的jdbc驱动太老了，<br />和ireport的不兼容····<br />建议到</font>
				<a href="http://dev.mysql.com/downloads/">
						<font color="#a52a2a">http://dev.mysql.com/downloads/</font>
				</a>
				<font color="#a52a2a">下载最新版本···</font>
		</p>
		<p>
				<font color="#a52a2a">5、配置数据库连接····<br />这个是报表与数据库的接口，通过&lt;资料来源&gt;--&lt;连接/资料来源&gt;开启配置对话框，ireport会记录以前使用的<br />所有连接，除非你手工删除这些连接，否则连接将一直存在···<br />配置新连接界面如下：<br /> <img alt=" " src="http://xiaoya317.blogchina.com/inc/o_1.jpg" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" /><br />提示：如果你需要报表提供中文内容显示可以在JDBC URL下工夫，比如输入：<br />jdbc:mysql://localhost/xiaoya?user=root&amp;password=root&amp;useUnicode=true&amp;characterEncoding=GB2312</font>
		</p>
		<p>
				<font color="#a52a2a">6、中文问题····<br />解决pdf中文问题需要下载itextasian.jar和itext-1.3.jar，将其下载后放到ireport/lib下即可··<br />要在这里提一下的是之前我也下载了这两个东东放到指定的位置了可还是乱码，后来还是解决了··<br />解决方法：<br />在iReport中新建一个TextField的时候会自动把pdf字体设为CP1252，这个是需要修改的，<br />否则pdf输出会报错说找不到字体，我就被这个捆饶了很久，修改如图：<br /><img alt=" " src="http://xiaoya317.blogchina.com/inc/font.gif" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" /></font>
		</p>
		<p>
				<font color="#a52a2a">7、理解几个重要的概念····<br />  a、iReport的输出格式····<br />    iReport的预览输出格式可以支持以下几种：<br />    PDF、HTML、CSV、JAVA2D、Excel、纯文字、JRViewer，其中最常用的是PDF、JRViewer。<br />    本文以JRViewer为例子。JRViewer是直接以C/S方式作为报表的输出格式，在JFrame框架下输出。Jasperreport提供默认的JRViewer输出类。<br />  b、报表的动态对象变量、参数、字段····<br />    在使用iReport的过程中会碰到很多与变量（Variables）、参数（Parameters）、字段（Fields）这些有关的内容，我们要介绍这些对象的使用和意义：<br />   ·字段（Fields）：是数据库抽取出来的，希望在报表中出现的数据库内容。<br />     比如一个ID的所有值。$F{ filedsName }<br />   ·参数（Parameters）：这是你的应用需要提供给报表的入口，<br />     比如你希望在报表被解释的时候提供Where语句的条件值，<br />     那么就可以使用参数（Parameters）。$P{ parameterName }<br />   ·变量（Variables）：这是报表中一些逻辑运算的表现，比如统计值。$V{ variablesName }<br />     每种对象的定义格式如每个对象的后面说明，比如定义一个变量（Variables），<br />     那么表达式就写成$V{ variablesName }，报表中出现的就是这个变量的名称。<br />   c、编译、静态运行、动态运行···<br />     Jasperreport运行时需要的就是一个jasper后缀的文件，编译过程其实就是把jrxml后缀的文件生成jasper后缀的文件。（可以参考Jasperreport的运行原理） 静态运行和动态运行是相对的，后者带数据源运行，比如带数据库运行。前者就是静态文本运行，和数据源无关，如果报表中出现和数据源有关的对象，则以null显示。<br />   d、报表的结构···<br />       一个报表的结构大致是几个部分：title、pageHeader、columnHeader、detial、columnFooter、pageFooter、summary、groupHeader、groupfooter。<br />     ·Title：每个报表一般会有一个名字，比如×××销售报表，title就是搁置这个名称的最好地方了，当然你也可以根据需要搁置在合适的地方。<br />     ·pageHeader：报表的一些公共要素，比如页码、创建时间、创建人等信息放置在这里是比较好的选择。<br />     ·columnHeader：无可非议的这里是放置列的名称，记住不是列数据。<br />     ·Detial：放置需要循环的数据，比如销售记录数据。<br />     ·columnFooter：放置列级别的统计计算值或是列的说明。<br />     ·pageFooter：放置页级别的统计值或是页的说明。<br />     ·Summary：可能需要对几页（你的报表可能有几个页组成）的统计值。比如50个销售记录共占用了3页，那么放置这些统计记录的统计值最好的地方就是summary。<br />     ·groupHeader：每个表的内容可能需要根据某个属性进行划分显示内容和计算内容，比如希望以月份为单位每组分开显示销售记录，那么就可以定义一个组（组的定义参考后文），groupHeader就是放置组说明或是组标志最好的地方。 <br />     ·Groupfooter：放置组的统计或是说明</font>
		</p>
		<p>
				<font color="#a52a2a">8、建立一个新的报表·····</font>
		</p>
		<p>
				<font color="#a52a2a">  a、新建一个空报表的基本配置<br />    单击工具栏的第一个工具“New Report”，新建一个报表，输入报表名称和定义报表的一些参数，比如名称输入（例子是做一个项目的Bug量统计报表）单击【More….】选择标签，填写或是选择XML编码，这是关系到你的XML支持的字符集的选择，请根据需要选择，比如需要你的XML文件支持中文，那么可以输入或是GBK，之后点击【OK】按钮，进入报表的设计界面。<br />  b、定义报表可能需要的字体类型及其属性<br />    一个报表的内容五花八门，有<nobr><a class="iAs" oncontextmenu="return false;" onmousemove="kwM(4);" onmouseover="kwE(event,4);" style="CURSOR: hand; COLOR: #0000ff; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="window.open('http://114.vnet.cn/search_web.html?id=148&amp;kw=表头','_blank');" onmouseout="kwL(event);" target="_blank">表头</a></nobr>、栏位名、数据、其他变量信息等等，如果这些信息都是一致的字体和属性（比如颜色），那么整个报表就死气沉沉，显得很粗糙了。我们可以在为报表添加每个元素时定义元素的属性，但是那是一个多么费时的工作，如果能预先定义一些属性的组合，之后在创建每个元素时只需选择这些组合的其中一个即可，省事又快速。<br />    单击【预览】－【报表字体】开启自定义组合对话框。单击【New】进入定义详细对话框，如图：<br />    按照图中的顺序填写信息和步骤，依次定义“表头”、“组”、“列”、“列内容”、“统计计算”、“其他”等6中字体组合。<br />    注意PDF内嵌字体的选择，如果你需要报表时以PDF文件格式提供，那么对此需要作出选择。<br />  <img alt=" " src="http://xiaoya317.blogchina.com/inc/o_3.jpg" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" />9、向表添加对象····<br />  a、添加静态对象···<br />   可以通过工具栏的工具添加静态对象，比如文本，点击【T】，之后在报表的空白处单击，如此即可把静态对象添加到报表，然后拖动对象的边框，使它的大小合适，双击对象弹出对象的属性配置对话框，切换到【Font】Label，在“Report font”的ComBox选择“表头”字体，（表头字体是前文提供的自定义属性组合），再切换到【Static Text】Label，修改表头的名字，比如“Bug统计报表”或是“销售记录统计表”等等与业务有关的内容。添加图片，请点击【Image Tool】，之后的操作与Text类似。其他静态对象操作步骤类似。<br />  b、使用连接···<br />    还记得前文提供的（3.2节）配置MySql数据库连接吗？这里我们将要使用前文配置的连接了。选择菜单【建立】－【使用动态连接】开启可选的动态连接， 选择任何一个你需要的连接最后【OK】，保存报表，这样你的报表就使用了这个连接了。<br />  <strong> *【特别提示】</strong>此连接必须与以后应用程序使用的连接一致。<br />  c、创建SQL查询语句····<br />    SQL语句是对任何RDBMS起作用的语言，外部用户需要使用这些语言管理维护数据库中的数据，同样的，iReport也是需要这么做，我们需要提供查询数据库的语言－SQL语句，这样，iReport即可通过此SQL语句获取数据，之后组织到报表中并显示出来，以满足用户的需要为目的。<br />    通过菜单【资料来源】－【报表查询】开启SQL输入对话框，并在【Report SQL Query】 Label中输入SQL语句如图：图中的“Automatically Retrieve Fields”checkbox和“ReadFields”Button是确认自动获取还是手动获取数据库表的可用Fields。单击【OK】，保存报表。<br />  <img style="WIDTH: 528px; HEIGHT: 470px" height="470" alt=" " src="http://xiaoya317.blogchina.com/inc/o_4.jpg" width="528" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" />  </font>
		</p>
		<p>
				<font color="#a52a2a">d、创建字段动态对象·····<br />    报表的动态对象有变量、参数、字段，前文提及了他们的概念，这里将要一一讲解如何使用。字段也就是数据库中的字段，通过菜单【预览】－【报表字段】开启字段的列表（工具条上可以找到相应的工具），可以拖放任意字段到报表的任何位置，比如拖动一部分Bug的内容字段到detial段（内容无关紧要，只要知道原理）。<br />  e、创建组···<br />     组是一个很重要的概念，一个报表可以多个组，每个组以一个关键字为标记，比如希望Bug统计是根据项目（或是产品）进行统计的。那么可以设立一个项目标记的组。如图：<br /> <br />    <img style="WIDTH: 518px; HEIGHT: 395px" height="395" alt=" " src="http://xiaoya317.blogchina.com/inc/o_5.jpg" width="518" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" />    </font>
		</p>
		<p>
				<font color="#a52a2a">组的参数设定可以看界面即可理解部分，其中最主要的是“Group expression”，这是必须输入格式正确的并且存在的字段名称，本文的“proname”是【字段】中的一个元素。依此类推，建立其他的组对象。<br />    每建立一个组，在报表的界面上都会出现该组对应的段，如图：他们是首尾对应出现的。（Header和Footer）<br />    <img style="WIDTH: 549px; HEIGHT: 410px" height="410" alt=" " src="http://xiaoya317.blogchina.com/inc/o_6.jpg" width="549" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" /><br />  <br />  f、添加参数和使用参数····<br />    我们重申参数作用，一般是需要外界提供参数给报表的入口，比如SQL语句的where条件的表达式。通过【预览】－【报表参数】开启报表参数列表对话框（工具条上可以找到相应的工具）。如图：输入名称及其他参数。【ok】,保存报表。<br />    <img alt=" " src="http://xiaoya317.blogchina.com/inc/o_7.jpg" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" />    那么如何使用呢？打开SQL语句对话框，参考“5.3创建SQL查询语句”，这时候的SQL语句应该是：SELECT * FROM bugs  where proname=$P{ProjectName} order by proname,modulename<br />    注意其中的红体字部分，就是把刚才定义的<nobr><a class="iAs" oncontextmenu="return false;" onmousemove="kwM(2);" onmouseover="kwE(event,2);" style="CURSOR: hand; COLOR: #0000ff; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="window.open('http://114.vnet.cn/search_web.html?id=148&amp;kw=变量','_blank');" onmouseout="kwL(event);" target="_blank">变量</a></nobr>运用到SQL语句了。这样当应用提供参数时，只要指定提供给这个参数，那么报表解释引擎即可替换这些变量然后再执行SQL语句，在第二部分提到编程时，会提供参数设定代码。<br />  <br />  g、添加变量和使用变量····<br />     变量的定义类似参数，通过【预览】－【报表变量】开启报表变量列表对话框（工具条上可以找到相应的工具），如图，图中定义的变量的作用是：定义一个Bug的计数器，数据类型是java.lang.Integer,使用Count函数进行统计字段tester，作用范围是模块组，也就是统计模块的Bug量。其中的tester可以改成其他非组对象，比如proname是组对象，就不要用作这里的统计参数。以上提供的是自定义变量，其实iReport系统还有提供一些内嵌（Buildin）的变量，比如页码，行记录数等，视需要而使用。<br />   <img style="WIDTH: 538px; HEIGHT: 575px" height="575" alt=" " src="http://xiaoya317.blogchina.com/inc/o_8.jpg" width="538" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" /><br />  <br />  10、最后的报表····<br />    a、完成后的报表···<br />     <img height="311" alt=" " src="http://xiaoya317.blogchina.com/inc/o_9.jpg" width="539" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" /><br />    b、预览报表···<br />     点击动态运行报表，出现如图内容：<br />      <img height="323" alt=" " src="http://xiaoya317.blogchina.com/inc/o_10.jpg" width="531" onload="function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA;function anonymous()&#xD;&#xA;{&#xD;&#xA; img_auto_size(this,450,true);&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}&#xD;&#xA;}" align="middle" /></font>
		</p>
		<p>
				<font color="#a52a2a">  11、在jsp中调用报表·····<br />    解决这个问题也用了我差不多2天时间:(，但总算是搞定了·····<br />    下面分别介绍以pdf格式和以html格式显示报表····<br />   a、pdf格式ireport_pdf.jsp····</font>
		</p>
		<p>
				<font color="#a52a2a">   &lt;%@ page import="net.sf.jasperreports.engine.*" %&gt;<br />    &lt;%@ page import="java.util.*" %&gt;<br />    &lt;%@ page import="java.io.*" %&gt;<br />    &lt;%@ page import="java.sql.*" %&gt;<br />    &lt;%<br />      //报表编译之后生成的.jasper 文件的存放位置<br />      File reportFile = new File(application.getRealPath("ireport/xueji.jasper"));<br />      //这个是用来联接我的mysql 的JDBC URL<br />      String url="jdbc:mysql://localhost:3306/xueji?useUnicode=true&amp;characterEncoding=gb2312";<br />      Class.forName("org.gjt.mm.mysql.Driver").newInstance();<br />      //传递报表中用到的参数值<br />      Map parameters = new HashMap();<br />     //"Name"是报表中定义过的一个参数名称,其类型为String 型</font>
		</p>
		<p>
				<font color="#a52a2a">     parameters.put("banji", new String(" c1"));<br />     System.out.println("---------conn-------------");<br />     //连接到<nobr><a class="iAs" oncontextmenu="return false;" onmousemove="kwM(5);" onmouseover="kwE(event,5);" style="CURSOR: hand; COLOR: #0000ff; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" onclick="window.open('http://114.vnet.cn/search_web.html?id=148&amp;kw=数据库','_blank');" onmouseout="kwL(event);" target="_blank">数据库</a></nobr><br />     Connection conn = DriverManager.getConnection(url,"root","root");<br />     System.out.println("---------Jasper begin-------------");<br />     //在控制台显示一下报表文件的物理路径<br />     System.out.println(reportFile.getPath());<br />     byte[] bytes=JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,conn);</font>
		</p>
		<p>
				<font color="#a52a2a">     System.out.println("---------Jasper end-------------");<br />     response.setContentType("application/pdf");<br />     response.setContentLength(bytes.length);<br />     ServletOutputStream ouputStream = response.getOutputStream();<br />     ouputStream.write(bytes, 0, bytes.length);<br />     ouputStream.flush();<br />     ouputStream.close();<br />   %&gt; </font>
		</p>
		<p>
				<!--page import="net.sf.jasperreports.engine.*"-->
				<font color="#a52a2a">   b、html格式ireport_html.jsp····</font>
		</p>
		<p>
				<font color="#a52a2a"> <!--page contentType="text/html; charset=gb2312"--><br />   <!--page import="net.sf.jasperreports.engine.*"--><br />   <!--page import="net.sf.jasperreports.engine.export.*"--><br />   <!--page import="net.sf.jasperreports.engine.util.*"--><br />   <!--page import="java.util.*"--><br />   <!--page import="java.io.*"--><br />   <!--page import="java.sql.*"--><br />   &lt;%</font>
		</p>
		<p>
				<br />
				<font color="#a52a2a">    File reportFile = new File(application.getRealPath("/ireport/xueji.jasper"));<br />    JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());<br />    Map parameters = new HashMap();<br />    parameters.put("baiji", "c1");<br />   //parameters.put("BaseDir", reportFile.getParentFile());    <br />   //JRBeanArrayDataSource jrDataSource = new JRBeanArrayDataSource(objects);//objects为要打印的实体数组；</font>
		</p>
		<p>
				<font color="#a52a2a">    Class.forName("org.gjt.mm.mysql.Driver");<br />    Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/xueji","root","root");<br />    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);<br />          <br />    JRHtmlExporter exporter = new JRHtmlExporter();<br />    StringBuffer sbuffer = new StringBuffer();</font>
		</p>
		<p>
				<font color="#a52a2a">    Map imagesMap = new HashMap();<br />    session.setAttribute("IMAGES_MAP", imagesMap);<br />    <br />    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);<br />    exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);<br />    //exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);<br />    //exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/ireport/ireport_html.Image?image="); <br />    //exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "<br style="PAGE-BREAK-BEFORE: always" />");<br />    exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);<br />    exporter.exportReport();<br />    //out.flush();<br />    conn.close();<br />   % &gt;</font>
		</p>
		<p>
				<font color="#a52a2a">注意：以html格式调用主要要注意//exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);<br />                              //exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "images目录的路径?image=");<br />                              在生成html预览的时候会生成一个px文件，而这个images_uri的路径就是那个px的路径，建议不用，就用下面<br />                              的语句就可以了···· <br />                              exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);    <br />而这个语句则是处理分页用的····                               <br />//exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "<br style="PAGE-BREAK-BEFORE: always" />");</font>
		</p>
		<p>
				<br />
				<font color="#a52a2a">需要注意的地方····<br />必须在tomcat5以上版本中运行····<br />在运行的时候还要将jasperreports/lib下的包全部拷到tomcat下你所放文件目录下的win-inf/lib下···<br />特别要注意的是看看ireport/lib下的包与jasperreports/lib的包是否兼容···<br />之前我的一直有问题就是因为我的发布环境是jasperreports-0.6.7.jar而运行环境是jasperreports-0.6.8.jar···<br />这样也会出现错误的····</font>
		</p>
		<p>
				<font color="#a52a2a">参考资料····<br />感谢···<br /></font>
				<a href="http://www-128.ibm.com/developerworks/cn/java/j-ireport/?ca=dwcn-newsletter-java">
						<font color="#a52a2a">http://www-128.ibm.com/developerworks/cn/java/j-ireport/?ca=dwcn-newsletter-java</font>
				</a>
				<br />
				<a href="http://blog.csdn.net/jemlee2002/archive/2004/10/05/125107.aspx">
						<font color="#a52a2a">http://blog.csdn.net/jemlee2002/archive/2004/10/05/125107.aspx</font>
				</a>
				<font color="#a52a2a">
				</font>
		</p>
<img src ="http://www.blogjava.net/43880800/aggbug/84155.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/43880800/" target="_blank">Tom</a> 2006-11-28 22:36 <a href="http://www.blogjava.net/43880800/archive/2006/11/28/84155.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>