Total Pageviews

2013/11/22

Why iReport eat my spaces

Requirement
We had a report requirement as bellows:
You can see some items' amount need to do indent. Others don't.

Problem
Here we add 7 single-byte spaces for some items' amount to do indent based on specific conditions.
1:   DecimalFormat df = new DecimalFormat();  
2:      df.setMaximumFractionDigits(2);  
3:      df.setMinimumFractionDigits(2);  
4:      for (Cta612pDto vo : dataList) {  
5:        if (StringUtils.startsWith(vo.getSeqnm(), "(*)") || "9800".equals(vo.getAcc())  
6:            || "9900".equals(vo.getAcc())) {  
7:          vo.setFormattedAmt(df.format(vo.getAmt()));  
8:        } else {  
9:          vo.setFormattedAmt(df.format(vo.getAmt()) + "       ");  
10:        }  
11:        formattedList.add(vo);  
12:      }  

But it does not work:

Root cause
 The iReport seem trim your spaces automatically. Therefore, it does not work for this circumstance.

Solution
We need to use double-byte spaces(全形空白) instead of single-byte spaces(半形空白).
1:   DecimalFormat df = new DecimalFormat();  
2:      df.setMaximumFractionDigits(2);  
3:      df.setMinimumFractionDigits(2);  
4:      for (Cta612pDto vo : dataList) {  
5:        if (StringUtils.startsWith(vo.getSeqnm(), "(*)") || "9800".equals(vo.getAcc())  
6:            || "9900".equals(vo.getAcc())) {  
7:          vo.setFormattedAmt(df.format(vo.getAmt()));  
8:        } else {  
9:          vo.setFormattedAmt(df.format(vo.getAmt()) + "   ");  
10:        }  
11:        formattedList.add(vo);  
12:      }  


No comments: