|
楼主 |
发表于 2014-10-21 11:48:04
|
显示全部楼层
您好,谢谢您回答了我的问题。我找到原因了,是导出XML文件时,现金流数值变成负数造成的(下面的图里标注的地方)。可是源代码我太会改,能不能麻烦您再给看一下,怎样改成正确的。谢谢了。
下面是源代码:
Public Sub tysetxml()
'power by HanShuo
Dim nian As String '年
nian = Range("d2").Value
Dim yue As String '月
yue = Range("e2").Value
Dim ri As String '日
ri = Range("f2").Value
Dim zhidan As String '制单人
zhidan = Range("b2").Value
Dim gongsiming As String '公司名
gongsiming = Range("b1").Value
Dim pzh As String
pzh = Range("d3").Value '取凭证号的值<voucher_id>
Dim djzs As String '定义单据张数
djzs = Range("b3").Value
Range("A6").Select
Dim fso As New FileSystemObject
Dim ts As TextStream
Dim flh As Integer
Dim zhaiyao As String
zhaiyao = ActiveCell.Offset(0, 1).Value '取摘要的值<abstract>
Dim kmbm As String
kmbm = ActiveCell.Offset(0, 2).Value '取值科目编码
Dim jfje As String
jfje = ActiveCell.Offset(0, 3).Value '取借方金额的值<primary_debit_amount><natural_debit_currency>
Dim dfje As String
dfje = ActiveCell.Offset(0, 4).Value '取贷方金额
Dim fzlx As String
fzlx = ActiveCell.Offset(0, 5).Value '取辅助类型的值
Dim fzbm As String
fzbm = ActiveCell.Offset(0, 6).Value '取辅助编码值
Dim cashflow As String
cashflow = ActiveCell.Offset(0, 7).Value '取现金流信息值
Dim fzlx2 As String
fzlx2 = ActiveCell.Offset(0, 8).Value '取2辅助类型的值
Dim fzbm2 As String
fzbm2 = ActiveCell.Offset(0, 9).Value '取2辅助编码值
flh = 1 '分录号<entry_id>
Set fso = New FileSystemObject
Set ts = fso.OpenTextFile(ThisWorkbook.Path & "\" & pzh & ".xml", 2, True)
ts.writeline ("<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(39) & "gb2312" & Chr(39) & "?>") '单引号39双引号34
ts.writeline ("<ufinterface billtype=" & Chr(34) & "gl" & Chr(34) & " codeexchanged=" & Chr(34) & "Y" & Chr(34) & " docid=" & Chr(34) & Chr(34) & " proc=" & Chr(34) & "add" & Chr(34) & " receiver=" & Chr(34) & "hfbhsg" & Chr(34) & " roottag=" & Chr(34) & "voucher" & Chr(34) & " sender=" & Chr(34) & "hfbhsg" & Chr(34) & ">")
ts.writeline "<voucher id=" & Chr(34) & Chr(34) & ">" '& pzid
ts.writeline "<voucher_head>"
ts.writeline "<company>" & gongsiming & "</company>"
ts.writeline "<voucher_type>通用凭证</voucher_type>"
ts.writeline "<fiscal_year>" & nian & "</fiscal_year>"
ts.writeline "<accounting_period>" & yue & "</accounting_period>"
ts.writeline "<voucher_id>" & pzh & "</voucher_id>"
ts.writeline "<attachment_number>" & djzs & "</attachment_number>"
ts.writeline "<date>" & nian & "-" & yue & "-" & ri & "</date>"
ts.writeline "<prepareddate>" & nian & "-" & yue & "-" & ri & "</prepareddate>"
ts.writeline "<enter>" & zhidan & "</enter>"
ts.writeline "<voucher_making_system>外部系统交换平台</voucher_making_system>"
ts.writeline "<memo1>Power By Hanshuo Hefei</memo1>"
ts.writeline "</voucher_head>"
ts.writeline "<voucher_body>"
'输出第一行收费分录
Do While ActiveCell.Value <> ""
ts.writeline "<entry>"
ts.writeline "<entry_id>" & flh & "</entry_id>"
ts.writeline "<account_code>" & kmbm & "</account_code>"
ts.writeline "<abstract>" & zhaiyao & "</abstract>"
ts.writeline "<currency>人民币</currency>"
ts.writeline "<unit_price>0.00000000</unit_price>"
ts.writeline "<exchange_rate1>0.00000000</exchange_rate1>"
ts.writeline "<exchange_rate2>1</exchange_rate2>"
ts.writeline "<primary_debit_amount>" & jfje & "</primary_debit_amount>"
ts.writeline "<natural_debit_currency>" & jfje & "</natural_debit_currency>"
ts.writeline "<primary_credit_amount>" & dfje & "</primary_credit_amount>"
ts.writeline "<natural_credit_currency>" & dfje & "</natural_credit_currency>"
If fzlx <> "" And fzbm <> "" Then
ts.writeline "<auxiliary_accounting>"
ts.writeline "<item name=" & Chr(34) & fzlx & Chr(34) & ">" & fzbm & "</item>"
If fzlx2 <> "" And fzbm2 <> "" Then
ts.writeline "<item name=" & Chr(34) & fzlx2 & Chr(34) & ">" & fzbm2 & "</item>"
End If
ts.writeline "</auxiliary_accounting>"
End If
If cashflow <> "" Then
ts.writeline "<otheruserdata>"
ts.writeline "<cashflowcase>"
ts.writeline "<money>" & Val(jfje) - Val(dfje) & "</money>"
ts.writeline "<moneyass></moneyass>"
ts.writeline "<moneymain>" & Val(jfje) - Val(dfje) & "</moneymain>"
ts.writeline "<pk_cashflow>" & cashflow & "</pk_cashflow>"
ts.writeline "</cashflowcase>"
ts.writeline "</otheruserdata>"
End If
ts.writeline "</entry>"
flh = flh + 1
ActiveCell.Offset(1, 0).Select
zhaiyao = ActiveCell.Offset(0, 1).Value '取摘要的值<abstract>
kmbm = ActiveCell.Offset(0, 2).Value '取值科目编码
jfje = ActiveCell.Offset(0, 3).Value '取借方金额的值<primary_debit_amount><natural_debit_currency>
dfje = ActiveCell.Offset(0, 4).Value '取贷方金额
fzlx = ActiveCell.Offset(0, 5).Value '取辅助类型的值
fzbm = ActiveCell.Offset(0, 6).Value '取辅助编码值
cashflow = ActiveCell.Offset(0, 7).Value '取现金流信息值
fzlx2 = ActiveCell.Offset(0, 8).Value '取2辅助类型的值
fzbm2 = ActiveCell.Offset(0, 9).Value '取2辅助编码值
Loop
ts.writeline "</voucher_body>"
ts.writeline "</voucher>"
ts.writeline "</ufinterface>"
ts.Close
Set ts = Nothing
Set fso = Nothing
MsgBox "你好"
End Sub
|
-
|