|
Sub WriteTxt(foldername As String, filename As String)
Dim fso As New FileSystemObject
Dim filepath1 As String, filepath2 As String
Dim txt As String
Dim tag As String, ssql As String
filepath1 = foldername & "\" & Replace(filename, ".txt", "") & ".txt"
fso.CreateTextFile filepath1, True
Open filepath1 For Output As 1#
'写入声明
txt = "<?xml version='1.0' encoding='GB2312'?>"
txt = Replace(txt, "'", Chr(34))
Print #1, txt
'写入Data节点
txt = "<Data TYPE='SPBIANMA'>"
txt = Replace(txt, "'", Chr(34))
Print #1, txt
'写入FENLEI节点
tag = "FENLEI"
ssql = "select "
ssql = ssql & "[/FENLEI/Row/@MC] as MC,"
ssql = ssql & "[/FENLEI/Row/@PID] as PID,"
ssql = ssql & "[/FENLEI/Row/@BM] as BM"
'ssql = ssql & "[/FENLEI/Row/@OLD_BM] as OLD_BM"
' ssql = ssql & "[/FENLEI/Row/@OLD_PID] as OLD_PID"
ssql = ssql & " from 表1 where ([/FENLEI/Row/@PID] is null)=false"
Call WriteRe(tag, ssql)
'写入SPXX节点
tag = "SPXX"
ssql = "select "
ssql = ssql & "[/SPXX/Row/@MC] as MC,"
ssql = ssql & "[/SPXX/Row/@PID] as PID,"
ssql = ssql & "[/SPXX/Row/@BM] as BM,"
ssql = ssql & "[/SPXX/Row/@HSBZ] as HSBZ,"
ssql = ssql & "[/SPXX/Row/@DJ] as DJ,"
ssql = ssql & "[/SPXX/Row/@JLDW] as JLDW,"
ssql = ssql & "[/SPXX/Row/@GGXH] as GGXH,"
ssql = ssql & "[/SPXX/Row/@SL] as SL,"
ssql = ssql & "[/SPXX/Row/@SPSM] as SPSM,"
ssql = ssql & "[/SPXX/Row/@JM] as JM "
'ssql = ssql & "[/SPXX/Row/@OLD_BM] as OLD_BM "
'ssql = ssql & "[/SPXX/Row/@OLD_PID] as OLD_PID "
'ssql = ssql & "[/SPXX/Row/@SCBM] as SCBM "
'ssql = ssql & "[/SPXX/Row/@SLLX] as SLLX "
'ssql = ssql & "[/SPXX/Row/@SPFLBM] as SPFLBM "
'ssql = ssql & "[/SPXX/Row/@SPFLBMPID] as SPDLBMPID "
'ssql = ssql & "[/SPXX/Row/@SYYHBZ] as SYYHBZ "
'ssql = ssql & "[/SPXX/Row/@YHZC] as YHZC "
ssql = ssql & " from 表1 where ([/SPXX/Row/@BM] is null)=false"
Call WriteRe(tag, ssql)
'写入Data闭合标签
Print #1, "</Data>"
Close #1
filepath2 = foldername & "\" & Replace(filename, ".txt", "") & ".xml"
If fso.FileExists(filepath2) = True Then
Kill filepath2
End If
Name filepath1 As filepath2
Set fso = Nothing
MsgBox "XML清单已成功导出!", vbInformation, "系统消息"
End Sub
为什么加了红色字体的那些语句就导不出来XML文件了,报错了,请百忙中能再次解答。谢谢
wuheng敬上 |
|