gpt4 book ai didi

java - 如何获取DynamicReports标题下的列?

转载 作者:行者123 更新时间:2023-12-01 09:42:13 24 4
gpt4 key购买 nike

enter image description here

我需要将列放在标题的正下方,并且中间不需要任何间隙。以及如何设置列的宽度?我已经给出了 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();
}
}

关于java - 如何获取DynamicReports标题下的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38366841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com