Office中国论坛/Access中国论坛

标题: 请教高手:打印人民币中文大写(多谢指点!) [打印本页]

作者: Tonyzhousammy    时间: 2004-3-2 18:44
标题: 请教高手:打印人民币中文大写(多谢指点!)
[B]各位高手,各位大哥:[/B]

       老板要求利用Access中的报表打印功能打印收费单据。但是,没有象Excel那样可以装一个转换函数转换成中文大写呀。急死人了!!   特向各位求救。[B]万分感谢!!![/B]
Tony
作者: 宿命的风    时间: 2004-3-2 19:17
http://www.office-cn.net/bbs/dispbbs.asp?boardID=2&ID=14123
这里面有一个的。(来自这个网站)
作者: Tonyzhousammy    时间: 2004-3-2 22:34
风大哥:
       非常感谢您的指点!  
       我对编程不太懂,我怎样在我的报表或者查询里调用你的程序呢?您能不能解释详细一点。非常感谢!

Tony


作者: sea.er    时间: 2004-3-3 08:05
你把他以下的东西拷到一个模块里,然后在用到的地方这样用:getdxje(你要转换的金额)

Private Function Num2Char(ByVal I As Integer) As String
If I >= 0 And I <= 9 Then
Num2Char = Mid$("零壹贰叁肆伍陆柒捌玖", I + 1, 1)
Else
Num2Char = ""
End If
End Function
Private Function Num2RMB(ByVal sFourBitString As String, Optional _
ByVal sUnit As String = "元", Optional ByVal bMustHeader As _
Boolean = False) As String
'----------------------------------------------------------------------
Dim vNum, I, RX, BR, hdr
'------------------------------------------------------------------
BR = "仟佰拾元"
'------------------------------------------------------------------
vNum = Trim(Str(Val(sFourBitString))) ' 最多四位
'------------------------------------------------------------------
If (Len(vNum) < 4 And Len(vNum) > 0) And bMustHeader Then hdr = "零" _
Else hdr = ""
RX = ""
Do While Len(vNum) > 0
I = Right(vNum, 1)
If I > 0 Then
RX = Num2Char(I) + Right(BR, 1) + RX
Else
If Left(RX, 1) <> "零" Then RX = "零" + RX
End If
vNum = Left(vNum, Len(vNum) - 1)
BR = Left(BR, Len(BR) - 1)
Loop
RX = Left(RX, Len(RX) - 1)
If Right(RX, 1) = "零" Then ' 去除多余的零
RX = Left(RX, Len(RX) - 1)
End If
If Len(RX) > 0 Then
Num2RMB = hdr + RX + sUnit
Else
Num2RMB = RX + IIf(sUnit = "元", "元", "")
End If
End Function
Function GetDXJE(ByVal Num As Currency) As String ' 得到大写金额
'----------------------------------------------------------------------
Dim vNum, vDec, ret, qb

'------------------------------------------------------------------
vNum = Right(Format(Int(Num), "000000000000"), 12) ' 取十二位整数
vDec = Right(Format(Int(Num * 100 + 0.5), "00"), 2) ' 取小数点后两位并自动四舍五入
'------------------------------------------------------------------
ret = Num2RMB(Left(vNum, 4), "亿", False)
If Len(ret) = 0 Then
ret = Num2RMB(Mid(vNum, 5, 4), "万", False)
Else
ret = ret + Num2RMB(Mid(vNum, 5, 4), "万", True)
End If
If Len(ret) = 0 Then
ret = Num2RMB(Right(vNum, 4), "元", False)
Else
ret = ret + Num2RMB(Right(vNum, 4), "元", True)
End If
'------------------------------------------------------------------
If ret = "元" Then
  ret = ""
  qb = ""
  Else
  qb = "xx"
End If
'------------------------------------------------------------------

If vDec = "00" And qb <> "" Then '1.00
    ret = ret + "整"
End If
If vDec = "00" And qb = "" Then '0.00
     ret = "(无金额)"
   
End If
   
If Left(vDec, 1) <> "0" And Right(vDec, 1) = 0 And qb <> "" Then '1.20
     ret = ret + Num2Char(Left(vDec, 1)) + "角整"
End If
If Left(vDec, 1) = "0" And Right(vDec, 1) <> 0 And qb <> "" Then '1.03
     ret = ret + "零" + Num2Char(Right(vDec, 1)) + "分"
End If
If Left(vDec, 1) <> "0" And Right(vDec, 1) <> 0 And qb <> "" Then '1.23
     ret = ret + Num2Char(Left(vDec, 1)) + "角" + Num2Char(Right(vDec, 1)) + "分"
End If
If Left(vDec, 1) <> "0" And Right(vDec, 1) = 0 And qb = "" Then '0.20
     ret = Num2Char(Left(vDec, 1)) + "角整"
End If
If Left(vDec, 1) = "0" And Right(vDec, 1) <> 0 And qb = "" Then '0.03
     ret = Num2Char(Right(vDec, 1)) + "分"
End If
If Left(vDec, 1) <> "0" And Right(vDec, 1) <> 0 And qb = "" Then '0.23
     ret = Num2Char(Left(vDec, 1)) + "角" + Num2Char(Right(vDec, 1)) + "分"
End If
   
GetDXJE = ret
'----------------------------------------------------------------------
End Function
作者: Tonyzhousammy    时间: 2004-3-4 05:40
问题解决了!!感谢指点!

       感谢斑竹以及风大哥的指点!非常好用。多谢多谢!!

Tony
作者: junta    时间: 2008-5-6 15:37
感谢!试试看。[:50]




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3