- 浏览: 544278 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (230)
- java (87)
- c/c++/c# (39)
- ASP.net MVC (4)
- eclipse/visual studio (3)
- tomcat/weblogic/jetty (13)
- linux/unix/windows (20)
- html/javascript/jquery/kendo/bootstrap/layui/vue/react (31)
- hibernate/struts/spring/mybatis/springboot (21)
- lucene/solr/ELK (2)
- shiro (0)
- oracle/sqlserver/mysql/postgresql (23)
- shell/python/ruby (6)
- android (0)
- maven/ant (1)
- freemarker/thymeleaf/velocity (1)
- open source project (41)
- cache/memcached/redis (0)
- nosql/hadoop/hbase/mongodb (0)
- system architecture/dubbo/zookeeper (0)
- software testing (0)
- system optimization (0)
- system security (0)
- tcp/udp/http (2)
- roller/wordpress (2)
- 工具收藏 (8)
- 文摘 (4)
- 生活 (0)
最新评论
-
coconut_zhang:
这个demo 非常完整了,是指下面说的那个html 模版,模版 ...
flying sauser, thymeleaf实现PDF文件下载 -
a93456:
你好,你有完整的demo吗? String template这 ...
flying sauser, thymeleaf实现PDF文件下载 -
yujiaao:
fn 函数循环是没有必要的啊,可以改成
protecte ...
Java 笛卡尔积算法的简单实现 -
安静听歌:
设置了.setUseTemporaryFileDuringWr ...
使用jxl导出大数据量EXCEL时内存溢出的解决办法 -
q280499693:
写的很详细,但是我现在想知道他们是怎么定位log4j.prop ...
关于SLF4J结合Log4j使用时日志输出与指定的log4j.properties不同
jasperreports 动态报表
Jasperreport的文档表明:
1> 开发静态报表建议采纳模板方式
2> 开发动态报表采用直接编辑JasperDesign对象。
但是似乎jasperreport对动态报表的操作缺乏高效率的工具类,因而开发
起来特别的费劲。
经过多方研究,得到了2种解决方案:
1> 结合Velocity技术动态生成jrxml模板文件;
2> 采用第三方工具DynamicJasper:DynamicJasper是sourceforge上的一个
开源项目,把它与jasperreport集成,可以相对轻松的解决大多数动态报表问题,
并且为进一步开发用户自定义报表提供了有效途径。
我采用的是第二种方案。
jasperreports是一个用来开发报表的组件,通常和ireport来配合使用,可以快速的构建出漂亮的报表。但是ireport画出的报表模板过于死板,就是不支持动态的列。现在要自己实现一个报表模板,先参考ireport工具画出的模板,然后改改,用java代码自己实现一个。
项目组目前就是这么做的,自己去写一个模板,一个横排的,一个竖排的,应为字段比较多,一般采用竖排的。我们项目组做动态报表没有用DynamicJasper这个开源的动态报表的组件,原因是我觉得他用起来也不太方便。还有就是时间的问题。
做了两个模板,现在备份下来。首先是横排的模板
package cn.hzmc.dynamicreport.example7;
import java.awt.Color;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRAlignment;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRReport;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.base.JRBaseLine;
import net.sf.jasperreports.engine.base.JRBasePrintText;
import net.sf.jasperreports.engine.design.JRDesignBand;
import net.sf.jasperreports.engine.design.JRDesignExpression;
import net.sf.jasperreports.engine.design.JRDesignField;
import net.sf.jasperreports.engine.design.JRDesignLine;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JRDesignStaticText;
import net.sf.jasperreports.engine.design.JRDesignStyle;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import net.sf.jasperreports.engine.design.JasperDesign;
import com.capaa.pipe.config.ReadConfig;
class Sample6 {
@SuppressWarnings("deprecation")
Sample6() throws Exception {
Connection connection = getConnection();
JasperDesign jasperDesign = new JasperDesign();
JRDesignStyle normalStyle = setReportSytle(jasperDesign);
JRDesignQuery query = new JRDesignQuery();
query.setText("select userid,name,age,sex,password,department from person");
jasperDesign.setQuery(query);
//addReportFiled(jasperDesign);
// Title
JRDesignBand band = new JRDesignBand();
band.setHeight(20);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setX(200);
staticText.setY(0);
staticText.setWidth(200);
staticText.setHeight(15);
staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT); //设置文本的对齐方式
staticText.setStyle(normalStyle);
staticText.setText("杭州美创科技有限公司审计报表 ");
band.addElement(staticText);
JRDesignLine line = new JRDesignLine();
line.setX(0);
line.setY(19);
line.setWidth(500);
line.setHeight(1);
line.setForecolor(new Color(0x99,0xFF,0xFF));
band.addElement(line);
jasperDesign.setTitle(band);
// Page header
band = new JRDesignBand();
//band.setHeight(20);
band.setHeight(0);
jasperDesign.setPageHeader(band);
// Column header
band = new JRDesignBand();
band.setHeight(20);
// 开始添加列字段
String[] headers = {"USERID","NAME","AGE","SEX","PASSWORD","DEPARTMENT"};
String[] alias = {"USERID","NAME","AGE","SEX","PASSWORD","DEPARTMENT"};
int X = 80;
int columnHeaderfontSize = 10;
int fontSize = 8;
int textHeight = 20;
int textWidth = 80;
int detailHeight = 20;
JRDesignBand detail = new JRDesignBand();
detail.setHeight(detailHeight);
for(int i = 0;i<headers.length;i++){
JRDesignStaticText jrstaticText = new JRDesignStaticText();
jrstaticText.setText(headers[i]);
jrstaticText.setFontSize(columnHeaderfontSize);
jrstaticText.setHeight(textHeight);
jrstaticText.setWidth(textWidth);
if(i==0){
X=0;
}else{
X = 80;
}
jrstaticText.setX(X * i);
jrstaticText.setPdfFontName("STSong-Light");
jrstaticText.setPdfEmbedded(true);
jrstaticText.setPdfEncoding("UniGB-UCS2-H");
// jrstaticText.setTextAlignment(JRBasePrintText.HORIZONTAL_ALIGN_CENTER);
// jrstaticText.setLeftBorder(JRBaseLine.PEN_1_POINT);
// jrstaticText.setTopBorder(JRBaseLine.PEN_1_POINT);
// jrstaticText.setRightBorder(JRBaseLine.PEN_1_POINT);
// jrstaticText.setBottomBorder(JRBaseLine.PEN_1_POINT);
jrstaticText.setForecolor(Color.blue);
// jrstaticText.setStretchType((byte)0);
band.addElement(jrstaticText);
// 定义字段,注册字段
JRDesignField field = new JRDesignField();
field.setName(alias[i]);
field.setValueClass(String.class);
jasperDesign.addField(field);
// add text fields for displaying fields
JRDesignTextField textField = new JRDesignTextField();
JRDesignExpression expression = new JRDesignExpression();
expression.setText("$F{" + alias[i] + "}");
expression.setValueClass(String.class);
textField.setExpression(expression);
textField.setFontSize(fontSize);
textField.setHeight(textHeight);
textField.setWidth(textWidth);
textField.setX(X * i);
textField.setPdfFontName("STSong-Light");
textField.setPdfEmbedded(true);
textField.setPdfEncoding("UniGB-UCS2-H");
textField.setTextAlignment(JRBasePrintText.HORIZONTAL_ALIGN_CENTER);
textField.setLeftBorder(JRBaseLine.PEN_1_POINT);
textField.setTopBorder(JRBaseLine.PEN_1_POINT);
textField.setRightBorder(JRBaseLine.PEN_1_POINT);
textField.setBottomBorder(JRBaseLine.PEN_1_POINT);
//textField.setForecolor(new Color(0x99,0xFF,0xFF));
textField.setForecolor(Color.blue);
textField.setStretchWithOverflow(true);
detail.addElement(textField);
}
jasperDesign.setColumnHeader(band);
//detail
jasperDesign.setDetail(detail);
// Column footer
band = new JRDesignBand();
band.setHeight(10);
jasperDesign.setColumnFooter(band);
// Page footer
band = new JRDesignBand();
band.setHeight(80);
staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(0);
staticText.setWidth(100);
staticText.setHeight(20);
staticText.setPdfFontName("STSong-Light");
staticText.setPdfEmbedded(true);
staticText.setPdfEncoding("UniGB-UCS2-H");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
staticText.setText(sdf.format(new Date()));
band.addElement(staticText);
JRDesignTextField textField = new JRDesignTextField();
textField.setX(450);
textField.setY(0);
textField.setWidth(100);
textField.setHeight(20);
textField.setPdfFontName("STSong-Light");
textField.setPdfEmbedded(true);
textField.setPdfEncoding("UniGB-UCS2-H");
JRDesignExpression expression = new JRDesignExpression();
expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("$V{PAGE_NUMBER}");
textField.setExpression(expression);
band.addElement(textField);
jasperDesign.setPageFooter(band);
System.out.println(expression.getText());
// Summary
band = new JRDesignBand();
band.setHeight(0);
/* **************************************************************** */
/* Here My doubt */
/*
* JRDesignChart chart1 = new
* JRDesignChart(null,JRChart.CHART_TYPE_LINE); chart1.setHeight(100);
* chart1.setBorderColor(Color.red); chart1.setForecolor(Color.BLACK);
* chart1.setWidth(200);
*/
// band.addElement(chart1);
jasperDesign.setSummary(band);
System.out.println("After Connection");
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
Map parameters = new HashMap();
System.out.println("After Parameter");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, connection);
System.out.println("After Print");
JasperExportManager.exportReportToHtmlFile(jasperPrint, "D://test2.html");
JasperExportManager.exportReportToPdfFile(jasperPrint, "D://test2.pdf");
JasperExportManager.exportReportToXmlFile(jasperPrint, "D://test2.xml", false);
System.out.println("After Export");
}
private void addReportFiled(JasperDesign jasperDesign) throws JRException {
JRDesignField field;
field=new JRDesignField();
field.setName("USERID");
field.setValueClass(java.math.BigDecimal.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("NAME");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("AGE");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("SEX");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("PASSWORD");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("DEPARTMENT");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
}
private JRDesignStyle setReportSytle(JasperDesign jasperDesign)
throws JRException {
jasperDesign.setName("SampleReport");
jasperDesign.setPageWidth(595);
jasperDesign.setPageHeight(842);
jasperDesign.setColumnWidth(535);
jasperDesign.setColumnSpacing(0);
jasperDesign.setLeftMargin(30);
jasperDesign.setRightMargin(30);
jasperDesign.setTopMargin(20);
jasperDesign.setBottomMargin(20);
// whenNoDataType="NoPages"
jasperDesign.setWhenNoDataType(JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE);
// isTitleNewPage="false"
jasperDesign.setTitleNewPage(false);
// isSummaryNewPage="false"
jasperDesign.setSummaryNewPage(false);
// jasperDesign.setOrientation(JRReport.ORIENTATION_PORTRAIT);
// jasperDesign.setPrintOrder(JRReport.PRINT_ORDER_VERTICAL);
JRDesignStyle normalStyle = new JRDesignStyle();
normalStyle.setName("Arial_Normal");
normalStyle.setDefault(true);
normalStyle.setFontName("Arial");
normalStyle.setFontSize(12);
normalStyle.setPdfFontName("STSong-Light");
normalStyle.setPdfEncoding("UniGB-UCS2-H");
normalStyle.setPdfEmbedded(true);
jasperDesign.addStyle(normalStyle);
JRDesignStyle boldStyle = new JRDesignStyle();
boldStyle.setName("Arial_Bold");
boldStyle.setFontName("Arial");
boldStyle.setFontSize(12);
boldStyle.setBold(true);
boldStyle.setPdfFontName("STSong-Light");
boldStyle.setPdfEncoding("UniGB-UCS2-H");
boldStyle.setPdfEmbedded(true);
jasperDesign.addStyle(boldStyle);
JRDesignStyle italicStyle = new JRDesignStyle();
italicStyle.setName("Arial_Italic");
italicStyle.setFontName("Arial");
italicStyle.setFontSize(12);
italicStyle.setItalic(true);
italicStyle.setPdfFontName("STSong-Light");
italicStyle.setPdfEncoding("UniGB-UCS2-H");
italicStyle.setPdfEmbedded(true);
jasperDesign.addStyle(italicStyle);
return normalStyle;
}
private Connection getConnection() throws SQLException {
Connection connection = ReadConfig.getProduceInstance().getDataSource()
.getConnection();
return connection;
}
}
class Sample {
public static void main(String args[]) throws Exception {
Sample6 obj = new Sample6();
}
}
然后是竖排的模板
package cn.hzmc.dynamicreport.example8;
import java.awt.Color;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRAlignment;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRReport;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.base.JRBaseLineBox;
import net.sf.jasperreports.engine.base.JRBasePrintText;
import net.sf.jasperreports.engine.design.JRDesignBand;
import net.sf.jasperreports.engine.design.JRDesignExpression;
import net.sf.jasperreports.engine.design.JRDesignField;
import net.sf.jasperreports.engine.design.JRDesignLine;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JRDesignStaticText;
import net.sf.jasperreports.engine.design.JRDesignStyle;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import net.sf.jasperreports.engine.design.JasperDesign;
import com.capaa.pipe.config.ReadConfig;
class Sample {
@SuppressWarnings("deprecation")
Sample() throws Exception {
Connection connection = getConnection();
JasperDesign jasperDesign = new JasperDesign();
JRDesignStyle normalStyle = setReportSytle(jasperDesign);
JRDesignQuery query = new JRDesignQuery();
query.setText("select userid,name,age,sex,password,department from person");
jasperDesign.setQuery(query);
//addReportFiled(jasperDesign);
// Title
JRDesignBand band = new JRDesignBand();
band.setHeight(20);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setX(200);
staticText.setY(0);
staticText.setWidth(200);
staticText.setHeight(15);
staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT); //设置文本的对齐方式
staticText.setStyle(normalStyle);
staticText.setText("杭州美创科技有限公司审计报表 ");
band.addElement(staticText);
JRDesignLine line = new JRDesignLine();
line.setX(0);
line.setY(19);
line.setWidth(500);
line.setHeight(1);
line.setForecolor(new Color(0x99,0xFF,0xFF));
band.addElement(line);
jasperDesign.setTitle(band);
// Page header
band = new JRDesignBand();
//band.setHeight(20);
band.setHeight(0);
jasperDesign.setPageHeader(band);
// Column header
band = new JRDesignBand();
band.setHeight(0);
jasperDesign.setColumnHeader(band);
//detail
// 开始添加列字段
String[] headers = {"USERID","NAME","AGE","SEX","PASSWORD","DEPARTMENT"};
String[] alias = {"USERID","NAME","AGE","SEX","PASSWORD","DEPARTMENT"};
int Y = 20;
int columnHeaderfontSize = 10;
int fontSize = 8;
int textHeight = 19;
int textWidth = 180;
int detailHeight = 130;
JRDesignBand detail = new JRDesignBand();
detail.setHeight(detailHeight);
for(int i=0;i<headers.length;i++){
}
for(int i = 0;i<headers.length;i++){
JRDesignStaticText jrstaticText = new JRDesignStaticText();
jrstaticText.setText(headers[i]);
jrstaticText.setFontSize(columnHeaderfontSize);
jrstaticText.setHeight(textHeight);
jrstaticText.setWidth(textWidth);
jrstaticText.setY(Y * i);
jrstaticText.setPdfFontName("STSong-Light");
jrstaticText.setPdfEmbedded(true);
jrstaticText.setPdfEncoding("UniGB-UCS2-H");
// jrstaticText.setTextAlignment(JRBasePrintText.HORIZONTAL_ALIGN_CENTER);
jrstaticText.setTextAlignment(JRBasePrintText.HORIZONTAL_ALIGN_LEFT);
/*jrstaticText.setLeftBorder(JRBaseLine.PEN_1_POINT);
jrstaticText.setTopBorder(JRBaseLine.PEN_1_POINT);
jrstaticText.setRightBorder(JRBaseLine.PEN_1_POINT);
jrstaticText.setBottomBorder(JRBaseLine.PEN_1_POINT); */
jrstaticText.setForecolor(Color.black);
// jrstaticText.setStretchType((byte)0);
// band.addElement(jrstaticText);
detail.addElement(jrstaticText);
// 定义字段,注册字段
JRDesignField field = new JRDesignField();
field.setName(alias[i]);
field.setValueClass(String.class);
jasperDesign.addField(field);
// add text fields for displaying fields
JRDesignTextField textField = new JRDesignTextField();
JRDesignExpression expression = new JRDesignExpression();
expression.setText("$F{" + alias[i] + "}");
expression.setValueClass(String.class);
textField.setExpression(expression);
textField.setFontSize(fontSize);
textField.setHeight(textHeight);
textField.setWidth(textWidth);
textField.setX(textWidth);
textField.setY(Y*i);
textField.setPdfFontName("STSong-Light");
textField.setPdfEmbedded(true);
textField.setPdfEncoding("UniGB-UCS2-H");
//textField.setTextAlignment(JRBasePrintText.HORIZONTAL_ALIGN_CENTER);
textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);
/*textField.setLeftBorder(JRBaseLine.PEN_1_POINT);
textField.setTopBorder(JRBaseLine.PEN_1_POINT);
textField.setRightBorder(JRBaseLine.PEN_1_POINT);
textField.setBottomBorder(JRBaseLine.PEN_1_POINT);*/
/*JRBaseLineBox baseLineBox = new JRBaseLineBox(textField);
baseLineBox.getLeftPen().setLineColor(Color.black);
baseLineBox.getLeftPen().setLineWidth(0);
baseLineBox.getLeftPen().setLineStyle((byte)0);
baseLineBox.getRightPen().setLineColor(Color.black);
baseLineBox.getRightPen().setLineWidth(0);
baseLineBox.getRightPen().setLineStyle((byte)0);
baseLineBox.getTopPen().setLineColor(Color.black);
baseLineBox.getTopPen().setLineWidth(0);
baseLineBox.getTopPen().setLineStyle((byte)0);
baseLineBox.getBottomPen().setLineColor(Color.black);
baseLineBox.getBottomPen().setLineWidth(0);
baseLineBox.getBottomPen().setLineStyle((byte)0);*/
//textField.setForecolor(new Color(0x99,0xFF,0xFF));
textField.setForecolor(Color.black);
textField.setStretchWithOverflow(true);
detail.addElement(textField);
}
// jasperDesign.setColumnHeader(band);
//detail
jasperDesign.setDetail(detail);
// Column footer
band = new JRDesignBand();
band.setHeight(0);
jasperDesign.setColumnFooter(band);
// Page footer
band = new JRDesignBand();
band.setHeight(20);
JRDesignLine line2 = new JRDesignLine();
line2.setX(0);
line2.setY(-10);
line2.setWidth(450);
line2.setHeight(0);
line2.setForecolor(new Color(0x99,0xFF,0xFF));
band.addElement(line2);
staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(0);
staticText.setWidth(100);
staticText.setHeight(20);
staticText.setPdfFontName("STSong-Light");
staticText.setPdfEmbedded(true);
staticText.setPdfEncoding("UniGB-UCS2-H");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
staticText.setText(sdf.format(new Date()));
band.addElement(staticText);
JRDesignTextField textField = new JRDesignTextField();
textField.setX(450);
textField.setY(0);
textField.setWidth(100);
textField.setHeight(20);
textField.setPdfFontName("STSong-Light");
textField.setPdfEmbedded(true);
textField.setPdfEncoding("UniGB-UCS2-H");
JRDesignExpression expression = new JRDesignExpression();
expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("$V{PAGE_NUMBER}");
textField.setExpression(expression);
band.addElement(textField);
jasperDesign.setPageFooter(band);
System.out.println(expression.getText());
// Summary
band = new JRDesignBand();
band.setHeight(0);
jasperDesign.setSummary(band);
System.out.println("After Connection");
JasperReport jasperReport = JasperCompileManager
.compileReport(jasperDesign);
Map parameters = new HashMap();
System.out.println("After Parameter");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
parameters, connection);
System.out.println("After Print");
JasperExportManager.exportReportToHtmlFile(jasperPrint, "D://test3.html");
JasperExportManager.exportReportToPdfFile(jasperPrint, "D://test3.pdf");
JasperExportManager.exportReportToXmlFile(jasperPrint, "D://test3.xml", false);
System.out.println("After Export");
}
private void addReportFiled(JasperDesign jasperDesign) throws JRException {
JRDesignField field;
field=new JRDesignField();
field.setName("USERID");
field.setValueClass(java.math.BigDecimal.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("NAME");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("AGE");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("SEX");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("PASSWORD");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
field = new JRDesignField();
field.setName("DEPARTMENT");
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);
}
private JRDesignStyle setReportSytle(JasperDesign jasperDesign)
throws JRException {
jasperDesign.setName("SampleReport");
jasperDesign.setPageWidth(595);
jasperDesign.setPageHeight(842);
jasperDesign.setColumnWidth(335);
jasperDesign.setColumnSpacing(0);
jasperDesign.setLeftMargin(30);
jasperDesign.setRightMargin(30);
jasperDesign.setTopMargin(20);
jasperDesign.setBottomMargin(20);
// whenNoDataType="NoPages"
jasperDesign.setWhenNoDataType(JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE);
// isTitleNewPage="false"
jasperDesign.setTitleNewPage(false);
// isSummaryNewPage="false"
jasperDesign.setSummaryNewPage(false);
// jasperDesign.setOrientation(JRReport.ORIENTATION_PORTRAIT);
// jasperDesign.setPrintOrder(JRReport.PRINT_ORDER_VERTICAL);
JRDesignStyle normalStyle = new JRDesignStyle();
normalStyle.setName("Arial_Normal");
normalStyle.setDefault(true);
normalStyle.setFontName("Arial");
normalStyle.setFontSize(12);
normalStyle.setPdfFontName("STSong-Light");
normalStyle.setPdfEncoding("UniGB-UCS2-H");
normalStyle.setPdfEmbedded(true);
jasperDesign.addStyle(normalStyle);
JRDesignStyle boldStyle = new JRDesignStyle();
boldStyle.setName("Arial_Bold");
boldStyle.setFontName("Arial");
boldStyle.setFontSize(12);
boldStyle.setBold(true);
boldStyle.setPdfFontName("STSong-Light");
boldStyle.setPdfEncoding("UniGB-UCS2-H");
boldStyle.setPdfEmbedded(true);
jasperDesign.addStyle(boldStyle);
JRDesignStyle italicStyle = new JRDesignStyle();
italicStyle.setName("Arial_Italic");
italicStyle.setFontName("Arial");
italicStyle.setFontSize(12);
italicStyle.setItalic(true);
italicStyle.setPdfFontName("STSong-Light");
italicStyle.setPdfEncoding("UniGB-UCS2-H");
italicStyle.setPdfEmbedded(true);
jasperDesign.addStyle(italicStyle);
return normalStyle;
}
private Connection getConnection() throws SQLException {
Connection connection = ReadConfig.getProduceInstance().getDataSource().getConnection();
return connection;
}
}
class Vertical {
public static void main(String args[]) throws Exception {
Sample obj = new Sample();
}
}
发表评论
-
easypoi 按照模板到出excel并合并单元格
2022-11-10 21:46 152这是entity类,注解的mergeVertical是纵向合 ... -
Java时区处理之Date,Calendar,TimeZone,SimpleDateFormat
2017-03-31 14:59 1372一、概述 1、问题描述 使用Java处 ... -
logback的使用和logback.xml详解
2017-03-09 11:20 2202一、logback的介绍 Logback是由log4j ... -
jxls操作excel文件
2017-03-03 14:51 1108JXLS是基于Jakarta POI API的Excel报表 ... -
jquery formValidator 表单验证插件, ajax无法传值到后台问题的解决
2016-06-24 17:10 671data : { count: Math.random ... -
thymeleaf与spring整合
2016-06-15 10:08 12401、使用的是Spring EL而不是Ognl。2、访问上下文 ... -
SpringMVC 400 Bad Request 问题
2016-06-15 09:11 1970在提交表单时,发生400错误,并未进入save方法。 ... -
bootstrap3自定义popover显示的内容
2016-05-27 11:14 1158<script type="text/jav ... -
eclipse插件Maven添加依赖查询无结果的解决方法(Select Dependency doesn't work)
2016-04-22 08:33 740在eclipse中用过maven的可能都遇到过这种情况,我 ... -
JS 中面向对象的5种写法
2015-08-13 15:54 710定义Circle类,拥有成员变量r,常量PI和计算面积的成员 ... -
动态载入/删除/更新外部 JavaScript/Css 文件的代码
2015-07-31 15:09 4125动态载入 JavaScript/Csss 文件 传统加载外部 ... -
Java_Ant详解
2015-06-15 16:54 7351,什么是antant是构建工 ... -
httpClient通过代理(Http Proxy)进行请求
2014-09-16 14:18 1240httpClient通过代理(Http Proxy)进行请求 ... -
httpclient上传文件及传参数
2014-09-16 11:07 11655用到的包有commons-httpclient-3.0.1. ... -
简单返回顶部代码及注释说明
2014-07-16 10:44 972最近做了一个排行榜页 ... -
深入浅出JSONP:解决AJAX跨域问题
2014-04-16 11:00 817取不到数据! 上周客户新买了服务器,原本在旧的服务器上放着 ... -
Progress Bar Plugin
2013-12-26 10:04 836from: http://digitalbush.com/p ... -
javascript cookie
2013-11-08 09:18 1070cookie概述在上一节, ... -
Java文件下载的几种方式
2013-08-19 14:15 881public HttpServletResponse dow ... -
http上传文件深度解析-高性能http传输
2013-07-23 10:41 9780最近在做web服务器的时候将一些应用集成在了服务器里面,比 ...
相关推荐
**使用JasperReports制作报表(导出PDF, Excel, HTML)** JasperReports是一款开源的Java报表库,它允许开发者...通过Java代码与报表模板的结合,可以方便地在应用程序中动态生成和导出报表,满足各种格式和数据需求。
然后,JasperReports引擎会根据这些模板和数据源动态生成报表,支持多种输出格式,如PDF、HTML、Excel、CSV等。 总的来说,JasperReports是一个强大且灵活的报表解决方案,广泛应用于各种Java应用中,为开发者提供...
iReport和JasperReports是Java世界中非常流行的报表设计和生成工具,它们为开发者提供了强大的报表解决方案。在本文中,我们将深入探讨这两个工具的核心特性、使用场景以及如何联合使用它们来创建复杂的JAVA报表。 ...
将Struts2与JasperReports结合使用,可以方便地在Web应用中实现动态报表的生成和展示。 首先,我们需要了解Struts2中整合JasperReports的基本步骤: 1. **环境准备**:确保你已经安装了MyEclipse开发环境,并且在...
JasperReports 是一款开源的报表工具,用于设计和生成各种类型的报表,包括 PDF、Excel、XML 等格式。在使用 JasperReports 生成报表时,你需要遵循以下详细流程: 1. **新建报表**: - 打开 JasperReports 设计...
7. **动态报表**:动态报表是JasperReports的一大特色,它允许在运行时改变报表的结构和内容,例如根据用户输入条件动态生成报表,或者在报表中加入实时数据。 通过阅读“JasperReports iRepor 报表开发详解.pdf”...
《iReport-JasperReports报表开发指南+操作手册》是一份详尽的资源,旨在帮助开发者深入理解和高效使用iReport和JasperReports这两个强大的报表工具。iReport是JasperReports的图形化设计工具,用于创建复杂的报表...
JasperReports是一款强大的开源报表工具,广泛应用于Java环境中,用于生成静态或动态的报告。在这个主题中,我们主要探讨如何使用JasperReports实现数据库查询并创建父子报表模板。 1. **JasperReports基础** ...
**JasperReports报表设计器——Jaspersoft Studio用户指南** JasperReports是一款强大的开源报表工具,其报表设计器——Jaspersoft Studio,是专为简化和优化报表创建而设计的集成开发环境(IDE)。这款强大的工具...
### iReport与JasperReports报表开发详解 #### 一、简介 JasperReports是一个功能强大的报表制作工具,它允许用户根据特定的规则编写XML文件,从而生成多种格式的输出文件,例如PDF、HTML、XML、XLS等。iReport则是...
基于struts2-jasperreports-plugin-2.3.1.2改写的插件,在原有功能的基础上又添加了多报表同时打印的功能。建议没用过struts2-jasperreports插件的先学习怎么使用这个插件。配的文档只对添加的功能的使用方法做了...
具体模版*.jrxml 博文链接:https://xiaobo.iteye.com/blog/34774
该小项目以编码形式实现了JaperReports的动态报表功能,以满足用户对报表的高度定制化。 使用该项目时的注意事项: 1.使用Eclipse导入该项目 2.下载JasperReports Library,将JasperReports的jar文件及其依赖jar...
你可以传递参数来动态调整报表内容。 5. **展示报表**:JasperExportManager或JasperViewer类可以用于导出或显示报表,支持多种格式,如PDF、HTML、Excel、CSV等。在Web环境中,通常会将报表导出为PDF或HTML,然后...
iReport是用于设计jasperReports报表的图形化界面,允许开发者使用拖拽方式创建和编辑报表模板。 以下是整合Struts2和jasperReports的步骤: 1. **引入依赖**:在项目的pom.xml或build.gradle文件中添加...
1. **iReport**:这是一个基于Java的报表设计工具,它允许开发者通过直观的用户界面创建、编辑和管理JasperReports报表模板。iReport支持多种数据源,包括数据库、CSV、XML等,并提供丰富的图表类型和样式选项。 2....
标题 "jasperreports打印word格式报表的问题" 涉及的是使用JasperReports库生成并打印Word(.doc或.docx)格式报表时遇到的技术挑战。JasperReports是一款开源Java库,它允许开发者创建、设计和导出各种类型的报告,...