如何在 DynamicReports 中获取标题下的列?
How to get column under the title in DynamicReports?
我需要将列放在标题的正下方,中间不需要任何间隙。以及如何为列设置宽度?我已经给了 setWidth(50)
但它没有得到并且边框覆盖了页面的整个右侧
这是我的代码:
public class DynamicReport {
public static void main(String[] args) {
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/marketing_database","root","root");
} catch (SQLException e) {
e.printStackTrace();
return;
} catch (ClassNotFoundException e) {
e.printStackTrace();
return;
}
JasperReportBuilder report = DynamicReports.report();//a new report
StyleBuilder plainStyle = stl.style().setFontName("FreeUniversal");
StyleBuilder boldStyle = stl.style(plainStyle).bold().setBorder(stl.pen1Point());
StyleBuilder col1style = stl.style().setBorder(stl.pen1Point());
report
.title(Components.text("Tax Invoice Cum Delivery Challan").setStyle(boldStyle)
.setHorizontalAlignment(HorizontalAlignment.CENTER))
.columns(col.column("", "companyName", type.stringType()).setWidth(50).setStyle(col1style))
.pageFooter(Components.pageXofY())
.setDataSource("SELECT companyName FROM marketing_database.company_profile",
connection);
try {
report.show();
report.toPdf(new FileOutputStream("c:/report.pdf"));
} catch (DRException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
如有任何帮助,我们将不胜感激
更新:
我知道了如何设置列宽。我使用了这段代码:
col.column("", "companyName", type.stringType()).setFixedWidth(20)
report
.columnHeader(//title of the report
Components.text("Tax Invoice Cum Delivery Challan").setStyle(boldStyle).setFixedHeight(10)
.setHorizontalAlignment(HorizontalAlignment.CENTER))
.columns(
col.column("", "companyName", type.stringType()).setFixedWidth(200).setStyle(col1style))
.pageFooter(Components.pageXofY())//show page number on the page footer
.setDataSource("SELECT companyName FROM marketing_database.company_profile",
connection);
try {
//show the report
report.show();
//export the report to a pdf file
report.toPdf(new FileOutputStream("c:/report.pdf"));
} catch (DRException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
我需要将列放在标题的正下方,中间不需要任何间隙。以及如何为列设置宽度?我已经给了 setWidth(50)
但它没有得到并且边框覆盖了页面的整个右侧
这是我的代码:
public class DynamicReport {
public static void main(String[] args) {
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/marketing_database","root","root");
} catch (SQLException e) {
e.printStackTrace();
return;
} catch (ClassNotFoundException e) {
e.printStackTrace();
return;
}
JasperReportBuilder report = DynamicReports.report();//a new report
StyleBuilder plainStyle = stl.style().setFontName("FreeUniversal");
StyleBuilder boldStyle = stl.style(plainStyle).bold().setBorder(stl.pen1Point());
StyleBuilder col1style = stl.style().setBorder(stl.pen1Point());
report
.title(Components.text("Tax Invoice Cum Delivery Challan").setStyle(boldStyle)
.setHorizontalAlignment(HorizontalAlignment.CENTER))
.columns(col.column("", "companyName", type.stringType()).setWidth(50).setStyle(col1style))
.pageFooter(Components.pageXofY())
.setDataSource("SELECT companyName FROM marketing_database.company_profile",
connection);
try {
report.show();
report.toPdf(new FileOutputStream("c:/report.pdf"));
} catch (DRException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
如有任何帮助,我们将不胜感激
更新:
我知道了如何设置列宽。我使用了这段代码:
col.column("", "companyName", type.stringType()).setFixedWidth(20)
report
.columnHeader(//title of the report
Components.text("Tax Invoice Cum Delivery Challan").setStyle(boldStyle).setFixedHeight(10)
.setHorizontalAlignment(HorizontalAlignment.CENTER))
.columns(
col.column("", "companyName", type.stringType()).setFixedWidth(200).setStyle(col1style))
.pageFooter(Components.pageXofY())//show page number on the page footer
.setDataSource("SELECT companyName FROM marketing_database.company_profile",
connection);
try {
//show the report
report.show();
//export the report to a pdf file
report.toPdf(new FileOutputStream("c:/report.pdf"));
} catch (DRException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}