在主报表中显示子报表的页码范围
Show Page number range of subreports in Master Report
我有一个主报表,其详细信息部分包含 4 个子报表。我想在主报告标题部分显示所有子报告的页码范围(例如 1-2)。我尝试使用子报告 return 值,但它仅在我有 1 个子报告时有效,如果有超过 1 个子报告
这是解决方案
Step1 : Create variables of any type inside each of the SubReport and the set the calculation, Increment Type and Reset Type to None. No need to specify the Expression as well Initial Value Expression
Step 2 : Create variables of String type inside the Master Report to hold the value of page number (eg. 1-2) and set the Calculation as System.
Step 3 : Add the variables created in Step2 on the Master Report Title section and set the evaluation time as Report.
Step 4 : Create scriptlet and set the page number in that
public class PageScriptlet extends JRDefaultScriptlet {
private static int mgmtReportPages;
private static int balanceSheetReportPages;
private static int incomeStmtReportPages;
private static int addInfoReportPages;
private static final String MGMT_REPORT_PAGENUM = "mgmtReportPageNum";
private static final String INCOME_STMT_PAGENUM = "incomeStmtPageNum";
private static final String BALANCE_SHEET_PAGENUM = "balanceSheetPageNum";
private static final String ADDINFO_PAGENUM = "addInfoPageNum";
private static final String MGMT_REPORT_INDEX = "mgmtReportIndex";
private static final String INCOMESTMT_INDEX = "incomeStmtIndex";
private static final String BALANCESHEET_INDEX = "balanceSheetIndex";
private static final String NOTES_INDEX = "notesIndex";
private static final String SIGNATURE_INDEX = "signatureIndex";
private static Integer firstPage = 2;
public PageScriptlet() {
super ();
}
@Override
public void afterPageInit() throws JRScriptletException{
Map<String, JRFillVariable> variablesMap = this.variablesMap;
if(variablesMap.containsKey(MGMT_REPORT_INDEX)){
Integer lastPage = mgmtReportPages+1;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(MGMT_REPORT_INDEX, index);
}
if(variablesMap.containsKey(INCOMESTMT_INDEX)){
Integer firstPage = mgmtReportPages + 2;
Integer lastPage = incomeStmtReportPages;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(INCOMESTMT_INDEX, index);
}
if(variablesMap.containsKey(BALANCESHEET_INDEX)){
Integer firstPage = incomeStmtReportPages+1;
Integer lastPage = balanceSheetReportPages;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(BALANCESHEET_INDEX, index);
}
if(variablesMap.containsKey(NOTES_INDEX)){
Integer firstPage = balanceSheetReportPages + 1;
Integer lastPage = addInfoReportPages;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(NOTES_INDEX, index);
}
if(variablesMap.containsKey(SIGNATURE_INDEX)){
Integer lastPage = addInfoReportPages;
String index = String.valueOf(lastPage);
this.setVariableValue(SIGNATURE_INDEX, index);
}
}
@Override
public void beforePageInit() throws JRScriptletException{
Map<String, JRFillVariable> variablesMap = this.variablesMap;
Integer pageNumber = (Integer)this.getVariableValue("PAGE_NUMBER");
if(variablesMap.containsKey(MGMT_REPORT_PAGENUM)){
mgmtReportPages = pageNumber == null ? 1 : pageNumber + 1;
}
if(variablesMap.containsKey(INCOME_STMT_PAGENUM)){
incomeStmtReportPages = pageNumber == null ? mgmtReportPages + 2 : incomeStmtReportPages + 1;
}
if(variablesMap.containsKey(BALANCE_SHEET_PAGENUM)){
balanceSheetReportPages = pageNumber == null ? incomeStmtReportPages + 1 : balanceSheetReportPages + 1;
}
if(variablesMap.containsKey(ADDINFO_PAGENUM)){
addInfoReportPages = pageNumber == null ? balanceSheetReportPages+1 : addInfoReportPages + 1;
}
}
}
我有一个主报表,其详细信息部分包含 4 个子报表。我想在主报告标题部分显示所有子报告的页码范围(例如 1-2)。我尝试使用子报告 return 值,但它仅在我有 1 个子报告时有效,如果有超过 1 个子报告
这是解决方案
Step1 : Create variables of any type inside each of the SubReport and the set the calculation, Increment Type and Reset Type to None. No need to specify the Expression as well Initial Value Expression
Step 2 : Create variables of String type inside the Master Report to hold the value of page number (eg. 1-2) and set the Calculation as System.
Step 3 : Add the variables created in Step2 on the Master Report Title section and set the evaluation time as Report.
Step 4 : Create scriptlet and set the page number in that
public class PageScriptlet extends JRDefaultScriptlet {
private static int mgmtReportPages;
private static int balanceSheetReportPages;
private static int incomeStmtReportPages;
private static int addInfoReportPages;
private static final String MGMT_REPORT_PAGENUM = "mgmtReportPageNum";
private static final String INCOME_STMT_PAGENUM = "incomeStmtPageNum";
private static final String BALANCE_SHEET_PAGENUM = "balanceSheetPageNum";
private static final String ADDINFO_PAGENUM = "addInfoPageNum";
private static final String MGMT_REPORT_INDEX = "mgmtReportIndex";
private static final String INCOMESTMT_INDEX = "incomeStmtIndex";
private static final String BALANCESHEET_INDEX = "balanceSheetIndex";
private static final String NOTES_INDEX = "notesIndex";
private static final String SIGNATURE_INDEX = "signatureIndex";
private static Integer firstPage = 2;
public PageScriptlet() {
super ();
}
@Override
public void afterPageInit() throws JRScriptletException{
Map<String, JRFillVariable> variablesMap = this.variablesMap;
if(variablesMap.containsKey(MGMT_REPORT_INDEX)){
Integer lastPage = mgmtReportPages+1;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(MGMT_REPORT_INDEX, index);
}
if(variablesMap.containsKey(INCOMESTMT_INDEX)){
Integer firstPage = mgmtReportPages + 2;
Integer lastPage = incomeStmtReportPages;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(INCOMESTMT_INDEX, index);
}
if(variablesMap.containsKey(BALANCESHEET_INDEX)){
Integer firstPage = incomeStmtReportPages+1;
Integer lastPage = balanceSheetReportPages;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(BALANCESHEET_INDEX, index);
}
if(variablesMap.containsKey(NOTES_INDEX)){
Integer firstPage = balanceSheetReportPages + 1;
Integer lastPage = addInfoReportPages;
String index = null;
if(firstPage == lastPage){
index = String.valueOf(firstPage);
}else{
index = String.valueOf(firstPage)+"-"+String.valueOf(lastPage);
}
this.setVariableValue(NOTES_INDEX, index);
}
if(variablesMap.containsKey(SIGNATURE_INDEX)){
Integer lastPage = addInfoReportPages;
String index = String.valueOf(lastPage);
this.setVariableValue(SIGNATURE_INDEX, index);
}
}
@Override
public void beforePageInit() throws JRScriptletException{
Map<String, JRFillVariable> variablesMap = this.variablesMap;
Integer pageNumber = (Integer)this.getVariableValue("PAGE_NUMBER");
if(variablesMap.containsKey(MGMT_REPORT_PAGENUM)){
mgmtReportPages = pageNumber == null ? 1 : pageNumber + 1;
}
if(variablesMap.containsKey(INCOME_STMT_PAGENUM)){
incomeStmtReportPages = pageNumber == null ? mgmtReportPages + 2 : incomeStmtReportPages + 1;
}
if(variablesMap.containsKey(BALANCE_SHEET_PAGENUM)){
balanceSheetReportPages = pageNumber == null ? incomeStmtReportPages + 1 : balanceSheetReportPages + 1;
}
if(variablesMap.containsKey(ADDINFO_PAGENUM)){
addInfoReportPages = pageNumber == null ? balanceSheetReportPages+1 : addInfoReportPages + 1;
}
}
}