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

摘要:
在水晶报表中也是可以添加函数的在报表空白出右键----报表----公式工作室在报表自定义函数中就可以增加自己的函数了FunctionAmountToWord2(dblAmountAsDouble)AsStringdimstrValueasstringstrValue=cstr(dblAmount)strValue=replace(strValue,",","")dimintLenValueasnu

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

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

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

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

以上代码原始作者不详

免责声明:文章转载自《在水晶报表中添加转换金额大写功能》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇12.tomcat7切换tomcat8导致cookie异常前端开发之观察者模式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C# 去除HTML标签

在做网站的时候,用到了去除html标签的问题,用正则匹配到html标签,然后replace即可。 /// <summary>/// C#去除HTML标签/// </summary>/// <param name="html">带有html标签的文本</param>/// <param name="len...

VS2015安装水晶报表

 最近在做一个打印功能,本来是不想用水晶报表的。想直接用微软原生的报表rdlc完成,但是整了一个上午老是打印乱码,且网上找资料找也找不出。 无奈放弃,然后就想到用水晶报表了,以前用过水晶报表,不过一直都是在VS2005、VS2008上用。搜索了下发现居然没有找到VS2015安装水晶报表的博文和下载地址。。。 最终还是被我找到了,贴出了方便大家,下面是地址:...

MySQL中使用replace into语句批量更新表数据

作为示例,我们在这里使用名为testdb的数据库,并且在其中创建两张一模一样的表: drop table if exists test_table_1; create table test_table_1 ( name varchar(30) primary key, age integer ); drop table if exists...

如何解决扩展AscII乱码噩梦

 今天公司站点遇到个问题:因为数据库设置的编码是GB的,所以一些法语字符存进去后立马乱码,更别说显示了,所以我想到了西文字符的显示方式。 如果你安装了DW,可以将首选参数的默认编码设置为希腊文,新建一个HTML页面你可以看到charset=iso-8859-7,OK,将其改为charset=iso-8859-1即可。 在拆分的下面输入框中输入汉字,嘿嘿,看...

过滤sql特殊字符方法集合

///<summary>///过滤不安全的字符串///</summary>///<param name="Str"></param>///<returns></returns>publicstaticstringFilteSQLStr(stringStr){Str=Str.Replac...

正则匹配 替换..追加..

这里都是以图片中的元素为例: 匹配出IMG标签中alt的值:1 Regex reg = new Regex(@"(?is)(?<=<img[^>]*alt="")[^""]*(?=""[^>]*>)"); 替换alt 内容: var replace = "alt='要替换的内容' "; source = Regex.Repl...