<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    spark的自留地(ofbiz/eclipse rcp/shark/opentaps)

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      54 Posts :: 0 Stories :: 112 Comments :: 0 Trackbacks

    我們在制作單證或報表時,客戶經(jīng)常要我們把最后的合計數(shù)轉(zhuǎn)寫中文大寫金額。這個需求很合理,但感覺并不容易實現(xiàn),如何在JasperReport中加入大寫金額的實現(xiàn)呢?提供一種實現(xiàn)的方法給大家參考。

    實現(xiàn)思路:
    在報表執(zhí)行過程中使用scirptlet將存放著數(shù)字金額的變量讀出轉(zhuǎn)換成大寫金額字符串后放入大寫金額變量中。報表即可象顯示普通字符變量一樣顯示大寫金額。


    TransChineseMoneyScriptlet.java代碼
      1/**
      2 * 大寫金額轉(zhuǎn)換Scriptlet類
      3 *
      4 * @author Spark (Email: spark.unt@gmail.com) 
      5 */

      6public class TransChineseMoneyScriptlet extends JRDefaultScriptlet {
      7    /*
      8     * 默認(rèn)構(gòu)造方法
      9     */

     10    public TransChineseMoneyScriptlet() {
     11    
     12    }

     13
     14    /**
     15     * 獲得金額的漢字大寫格式 <br>
     16     * @param money 小寫金額字符串
     17     * @return 大寫的漢字金額
     18     */

     19    public static String getChineseMoney(String money) {
     20        String text = transChineseMoney1(money) + transChineseMoney2(money);
     21        Pattern p = Pattern.compile("零分", Pattern.CASE_INSENSITIVE);
     22        Matcher m = p.matcher(text);
     23        text = m.replaceAll("");
     24        return text;
     25    }

     26
     27    /**
     28     * 截得輸入金額的整數(shù)部分,并將其轉(zhuǎn)換成中文大寫的格式 <br>
     29     * <br>
     30     * 其他描述:輸入數(shù)字超過接受范圍時拒絕轉(zhuǎn)換并退出。<br>
     31     * @param 傳遞參數(shù)字符串S 參數(shù)描述
     32     * @return 返回轉(zhuǎn)換后的字符串
     33     */

     34    public static String transChineseMoney1(String s) {
     35        String ss = s;
     36        String tmpnewchar = "";
     37        String[] part = ss.split("\\.");
     38
     39        if (part[0].length() > 10{
     40            // 超出可轉(zhuǎn)換位數(shù)
     41            return "";
     42        }

     43        for (int i = 0; i < part[0].length(); i++{
     44            char perchar = part[0].charAt(i);
     45            if (perchar == '0')
     46                tmpnewchar = tmpnewchar + "";
     47            if (perchar == '1')
     48                tmpnewchar = tmpnewchar + "";
     49            if (perchar == '2')
     50                tmpnewchar = tmpnewchar + "";
     51            if (perchar == '3')
     52                tmpnewchar = tmpnewchar + "";
     53            if (perchar == '4')
     54                tmpnewchar = tmpnewchar + "";
     55            if (perchar == '5')
     56                tmpnewchar = tmpnewchar + "";
     57            if (perchar == '6')
     58                tmpnewchar = tmpnewchar + "";
     59            if (perchar == '7')
     60                tmpnewchar = tmpnewchar + "";
     61            if (perchar == '8')
     62                tmpnewchar = tmpnewchar + "";
     63            if (perchar == '9')
     64                tmpnewchar = tmpnewchar + "";
     65
     66            int j = part[0].length() - i - 1;
     67            if (j == 0)
     68                tmpnewchar = tmpnewchar + "";
     69            if (j == 1 && perchar != 0)
     70                tmpnewchar = tmpnewchar + "";
     71            if (j == 2 && perchar != 0)
     72                tmpnewchar = tmpnewchar + "";
     73            if (j == 3 && perchar != 0)
     74                tmpnewchar = tmpnewchar + "";
     75            if (j == 4 && perchar != 0)
     76                tmpnewchar = tmpnewchar + "";
     77            if (j == 5 && perchar != 0)
     78                tmpnewchar = tmpnewchar + "";
     79            if (j == 6 && perchar != 0)
     80                tmpnewchar = tmpnewchar + "";
     81            if (j == 7 && perchar != 0)
     82                tmpnewchar = tmpnewchar + "";
     83            if (j == 8 && perchar != 0)
     84                tmpnewchar = tmpnewchar + "";
     85            if (j == 9 && perchar != 0)
     86                tmpnewchar = tmpnewchar + "";
     87        }

     88        return tmpnewchar;
     89    }

     90
     91    /**
     92     * 截得輸入金額的小數(shù)部分,并將其轉(zhuǎn)換成中文大寫的格式 <br>
     93     * <br>
     94     * 其他描述:小數(shù)部分超過兩位時系統(tǒng)自動截斷。<br>
     95     * 
     96     * @param 傳遞參數(shù)字符串
     97     * 
     98     * @return 返回轉(zhuǎn)換后的字符串
     99     */

    100    public static String transChineseMoney2(String s) {
    101        String ss = s;
    102        String tmpnewchar1 = "";
    103        String[] part = ss.split("\\.");
    104
    105        if (ss.indexOf("."!= -1{
    106            if (part[1].length() > 2{
    107                // MessageDialog.openInformation(null,"提示","小數(shù)點之后只能保留兩位,系統(tǒng)將自動截段");
    108                part[1= part[1].substring(02);
    109            }

    110            for (int i = 0; i < part[1].length(); i++{
    111                char perchar = part[1].charAt(i);
    112//                System.out.println(perchar);
    113                if (perchar == '0')
    114                    tmpnewchar1 = tmpnewchar1 + "";
    115                if (perchar == '1')
    116                    tmpnewchar1 = tmpnewchar1 + "";
    117                if (perchar == '2')
    118                    tmpnewchar1 = tmpnewchar1 + "";
    119                if (perchar == '3')
    120                    tmpnewchar1 = tmpnewchar1 + "";
    121                if (perchar == '4')
    122                    tmpnewchar1 = tmpnewchar1 + "";
    123                if (perchar == '5')
    124                    tmpnewchar1 = tmpnewchar1 + "";
    125                if (perchar == '6')
    126                    tmpnewchar1 = tmpnewchar1 + "";
    127                if (perchar == '7')
    128                    tmpnewchar1 = tmpnewchar1 + "";
    129                if (perchar == '8')
    130                    tmpnewchar1 = tmpnewchar1 + "";
    131                if (perchar == '9')
    132                    tmpnewchar1 = tmpnewchar1 + "";
    133
    134                if (i == 0 && perchar != 0)
    135                    tmpnewchar1 = tmpnewchar1 + "";
    136                if (i == 1 && perchar != 0)
    137                    tmpnewchar1 = tmpnewchar1 + "";
    138            }

    139        }

    140        return tmpnewchar1;
    141    }

    142
    143
    144/** Begin EVENT_AFTER_COLUMN_INIT This line is generated by iReport. Don't modify or move please! */
    145public void afterColumnInit() throws JRScriptletException
    146{
    147    super.beforeColumnInit();
    148}

    149/** End EVENT_AFTER_COLUMN_INIT This line is generated by iReport. Don't modify or move please! */
    150/** Begin EVENT_AFTER_DETAIL_EVAL This line is generated by iReport. Don't modify or move please! */
    151public void afterDetailEval() throws JRScriptletException
    152{
    153    Double sumTaxMoney = getVariableValue("sumTaxMoney"== null ? new Double(0.0)
    154    : (java.lang.Double) getVariableValue("sumTaxMoney");
    155
    156//    System.out.println("sumTaxMoney = " + sumTaxMoney);
    157    String cnMoney = getChineseMoney(sumTaxMoney+"");
    158//    System.out.println("cnMoney = " + cnMoney);
    159    this.setVariableValue("cnMoney", cnMoney);
    160    super.afterDetailEval();
    161}

    162/** End EVENT_AFTER_DETAIL_EVAL This line is generated by iReport. Don't modify or move please! */
    163/** Begin EVENT_AFTER_GROUP_INIT This line is generated by iReport. Don't modify or move please! */
    164public void afterGroupInit(String groupName) throws JRScriptletException
    165{
    166    super.afterGroupInit(groupName);
    167}

    168/** End EVENT_AFTER_GROUP_INIT This line is generated by iReport. Don't modify or move please! */
    169/** Begin EVENT_AFTER_PAGE_INIT This line is generated by iReport. Don't modify or move please! */
    170public void afterPageInit() throws JRScriptletException
    171{
    172    super.afterPageInit();
    173}

    174/** End EVENT_AFTER_PAGE_INIT This line is generated by iReport. Don't modify or move please! */
    175/** Begin EVENT_AFTER_REPORT_INIT This line is generated by iReport. Don't modify or move please! */
    176public void afterReportInit() throws JRScriptletException
    177{
    178    
    179    
    180    
    181}

    182/** End EVENT_AFTER_REPORT_INIT This line is generated by iReport. Don't modify or move please! */
    183/** Begin EVENT_BEFORE_COLUMN_INIT This line is generated by iReport. Don't modify or move please! */
    184public void beforeColumnInit() throws JRScriptletException
    185{
    186        
    187}

    188/** End EVENT_BEFORE_COLUMN_INIT This line is generated by iReport. Don't modify or move please! */
    189/** Begin EVENT_BEFORE_DETAIL_EVAL This line is generated by iReport. Don't modify or move please! */
    190public void beforeDetailEval() throws JRScriptletException
    191{
    192    
    193}

    194/** end EVENT_BEFORE_DETAIL_EVAL Please don't touch or move this comment*/
    195
    196/** End EVENT_BEFORE_DETAIL_EVAL This line is generated by iReport. Don't modify or move please! */
    197/** Begin EVENT_BEFORE_GROUP_INIT This line is generated by iReport. Don't modify or move please! */
    198public void beforeGroupInit(String groupName) throws JRScriptletException
    199{
    200    
    201}

    202/** End EVENT_BEFORE_GROUP_INIT This line is generated by iReport. Don't modify or move please! */
    203/** Begin EVENT_BEFORE_PAGE_INIT This line is generated by iReport. Don't modify or move please! */
    204public void beforePageInit() throws JRScriptletException
    205{
    206    
    207}

    208/** End EVENT_BEFORE_PAGE_INIT This line is generated by iReport. Don't modify or move please! */
    209/** Begin EVENT_BEFORE_REPORT_INIT This line is generated by iReport. Don't modify or move please! */
    210public void beforeReportInit() throws JRScriptletException
    211{
    212    
    213}

    214
    215/** End EVENT_BEFORE_REPORT_INIT This line is generated by iReport. Don't modify or move please! */
    216
    217}

    后面幾個方法都是iReport所需的幾個方法,不要刪除掉它。

    然后在報表中將定義兩個報表變量:
    sumTaxMoney  用于存放小寫金額,它是Double型,并在iReport中寫上計算公式或script
    cnMoney 用于接收本scriptlet傳回的大寫金額變量,在iReport中無需賦值,直接放到需顯示的地方即可
    jasperreport單據(jù)報表

    用紅框框起來的部分就是我們想要的結(jié)果,是不是很酷呀?

    差點忘記了關(guān)鍵的啦,要在你的報表XML中jasperReport節(jié)點中增加以下屬性值scriptletClass="TransChineseMoneyScriptlet" ,來啟用該scriptlet
    posted on 2008-11-19 12:20 shanghai_spark 閱讀(4128) 評論(13)  編輯  收藏 所屬分類: pentaho & jasperreport

    Feedback

    # re: 在JasperReport報表中加入大寫金額 2008-11-19 15:38 凌晨風(fēng)
    哥們!有研究過純Java代碼做一個crosstab嗎?我現(xiàn)在在做這個接口,能交流下嗎?  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2008-11-19 19:37 廣州spark
    @凌晨風(fēng)
    jasper report或是別的報表引擎如birt做個crosstab是很容易的呀,它們都是純java的實現(xiàn),你要重新發(fā)明輪子嗎?  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2008-11-19 22:02 扭曲的鉛筆
    你好,你現(xiàn)在用JasperReport和ireport的版本是多少?
    想向您學(xué)習(xí)學(xué)習(xí)。  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2008-11-19 22:21 廣州spark
    @扭曲的鉛筆
    說起來很慚愧,最近三年都沒更新過版本了,一直在用1.2.5,真的沒覺得有什么不夠用. 而且一個東西用久了有一個好處,連它的一些bug你都知道甚至喜歡在哪里了.如果你是初學(xué)者的話,當(dāng)然用最新的也沒問題,不過不要用nb版.那個玩意對中文支持不好. 做報表是一個細(xì)致的活,格式與復(fù)雜的查詢都很折磨人,鍛煉性情非常棒!  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2008-11-20 10:34 凌晨風(fēng)
    我們這邊需要提供給別人接口,而Ireport做的交叉報表功能有限啊!  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2008-11-20 18:57 廣州spark
    @凌晨風(fēng)
    或許你可以談下你的需求,我想如果iReport做不到,再考慮自己實現(xiàn),但實際上我們往往會以后它們沒想過.這種傻事我干過N次了.所以現(xiàn)在做什么都要先找下有無更好的解決方案.  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2008-11-21 14:00 凌晨風(fēng)
    我們這邊有自己的報表系統(tǒng),集成了好多優(yōu)秀的報表,現(xiàn)在對jasperReport的支持不是很好,有時間私聊吧!laoshulin@gmail.com  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2009-06-20 17:42 leoyang
    你好,看了您的文章,我試了一下,沒有成功,不知道是哪兒出了問題,變量cnMoney沒有出現(xiàn)大寫金額,是不是還需要設(shè)置其他的地方,這是我的郵箱:leoyang0123@126.com 請教您能否給解決一下  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額[未登錄] 2012-06-05 17:23 charles
    呵呵,我最近用開發(fā)用到birt,但是ofbiz里面birt有問題,或者說,目前沒調(diào)通。我想,我們應(yīng)該成為朋友。扣扣:一零五三七二二九零  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2013-04-24 10:22
    啊  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額[未登錄] 2013-04-24 10:23
    您好,看了您的帖,還是沒能實現(xiàn)效果,那個寫的java 類是怎么引導(dǎo)irpeoret 里面去的??????  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2013-05-04 10:01 搜索
    您好,您寫的類有bug , 如38707.20,大寫出來,有問題  回復(fù)  更多評論
      

    # re: 在JasperReport報表中加入大寫金額 2013-05-04 17:55 搜索
    您的帖子,有很多的dug ,如當(dāng) 金額為整數(shù)時,1000 ,為壹仟零佰零零元零角,這樣的  回復(fù)  更多評論
      


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 精品久久久久久久免费人妻| 最新中文字幕电影免费观看| 免费无遮挡无码永久视频| 一级毛片不卡片免费观看| 免费福利在线播放| 成年人免费网站在线观看| 国产成人免费福利网站| 4338×亚洲全国最大色成网站| 久久精品九九亚洲精品天堂| 精品亚洲成a人片在线观看| 亚洲毛片无码专区亚洲乱| 亚洲综合无码一区二区痴汉| 国产精品久久亚洲一区二区| 日本三级在线观看免费| 18女人腿打开无遮掩免费| 四虎影院免费在线播放| 亚洲国产综合无码一区二区二三区| 亚洲AV无码一区二区乱子伦 | 国产最新凸凹视频免费| 国产国拍亚洲精品福利| 亚洲精品欧洲精品| 日韩国产欧美亚洲v片| 99精品免费视频| 国内精品乱码卡1卡2卡3免费| 国产大片51精品免费观看| 国产l精品国产亚洲区在线观看| 91亚洲精品自在在线观看| 国产精品亚洲а∨无码播放不卡 | 四虎影视免费永久在线观看| 久久亚洲国产成人精品性色| 国产无遮挡吃胸膜奶免费看视频 | 亚洲精品线在线观看| 青青草原精品国产亚洲av| 亚洲AV第一成肉网| 亚洲av片在线观看| 久久aⅴ免费观看| 日韩精品无码人妻免费视频| 亚洲今日精彩视频| 日韩成人毛片高清视频免费看| 69国产精品视频免费| 亚洲色欲久久久久综合网|