小隐的博客

人生在世,笑饮一生
随笔 - 304, 文章 - 0, 评论 - 349, 阅读 - 50万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

在水晶报表中添加转换金额大写功能

Posted on   隐客  阅读(631)  评论(0编辑  收藏  举报

在水晶报表中也是可以添加函数的

在报表空白出右键----报表----公式工作室

在报表自定义函数中就可以增加自己的函数了

Function   AmountToWord2(dblAmount   As   Double)   As   String   

dim strValue as string          

strValue=cstr(dblAmount)

strValue=replace(strValue,",","")

dim intLenValue as number       

intLenValue=len(strValue)

dim intDecPos as number

intDecPos=instr(strValue,".")

dim strInt as string

dim intLenInt as number

dim strDec as string            

dim intLenDec as number

if intDecPos>0 then

    '整数位

    intLenInt=intDecPos-1

    strInt=mid(strValue,1,intLenInt)

    '小数位

    intLenDec=intLenValue-(intDecPos+1)+1  

    strDec=mid(strValue,intDecPos+1,intLenDec)    

else

    intLenInt=intLenValue

    strInt=strValue

end if

'1兆一下的金额

dim i as number

i=1

'整数位处理

dim strIntB as string

strIntB=""

dim intIndex as number

intIndex=1

for i=intLenInt to 1 step -1

    intIndex=intLenInt-i+1

    select case i    

        case 1            

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + mid(strInt,intIndex,1)             

        case 2

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "拾"            

        case 3

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "佰"                        

        case 4

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "仟"            

        case 5

            strIntB=strIntB + mid(strInt,intIndex,1) 

            'if ToNumber(mid(strInt,intIndex,1))>0 then 

                strIntB=strIntB + "万"

            'end if

        case 6

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "拾"        

        case 7

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "佰"

        case 8

            strIntB=strIntB + mid(strInt,intIndex,1)

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "仟"

        case 9

            strIntB=strIntB + mid(strInt,intIndex,1)        

            'if ToNumber(mid(strInt,intIndex,1))>0 then 

                strIntB=strIntB + "亿"                

            'end if

        case 10

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "拾"

        case 11

            strIntB=strIntB + mid(strInt,intIndex,1) 

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "佰"    

        case 12

            strIntB=strIntB + mid(strInt,intIndex,1)

            if ToNumber(mid(strInt,intIndex,1))>0 then strIntB=strIntB + "仟"        

    end select    

next i

if strIntB<>"" then

    strIntB=strIntB + "元"

end if

strIntB=Replace(strIntB,"1拾","拾")

for i=1 to 10

    strIntB = Replace(strIntB,"00","0")

next i

strIntB = Replace(strIntB,"0元","元")

strIntB = Replace(strIntB,"0万","万")

'小数处理

dim strDecB as string

strDecB=""

i=1

select case intLenDec

    case 1

        '# –> #角

        if ToNumber(mid(strDec,i,1))>0 then strDecB=strDec +"角"        

    case 2

        '## –> #角#分        

        if strIntB <>"" then     

            strDecB=strDecB + mid(strDec,i,1) 

            if ToNumber(mid(strDec,i,1))>0 then strDecB=strDecB +"角"               

        else

            if ToNumber(mid(strDec,i,1))>0 then strDecB=strDecB + mid(strDec,i,1) +"角"

        end if

        i=i+1

        if ToNumber(mid(strDec,i,1))>0 then strDecB=strDecB + mid(strDec,i,1) +"分"                   

end select

if strDecB="0" then strDecB=""

dim strValueB as string

if strDecB<>"" then

    strValueB=strIntB + strDecB     

else

    if strIntB<>"" then

        strValueB=strIntB + "整"

    else

        strValueB=strIntB + "0元整"

    end if

end if

strValueB = Replace(strValueB,"0元","元")

strValueB = Replace(strValueB,"0","零")

strValueB = Replace(strValueB,"1","壹")

strValueB = Replace(strValueB,"2","贰")

strValueB = Replace(strValueB,"3","叁")

strValueB = Replace(strValueB,"4","肆")

strValueB = Replace(strValueB,"5","伍")

strValueB = Replace(strValueB,"6","陆")

strValueB = Replace(strValueB,"7","柒")

strValueB = Replace(strValueB,"8","捌")

strValueB = Replace(strValueB,"9","玖")

AmountToWord2=strValueB

End   Function

以上代码原始作者不详

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
QQ交流
点击右上角即可分享
微信分享提示