设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: wuheng
打印 上一主题 下一主题

[Access本身] 如何把表导出成固定格式的XML文件

[复制链接]
11#
 楼主| 发表于 2015-1-29 14:29:22 | 只看该作者
终于整好了~~~~~~~~~~~再次对两位大侠表示感谢~~~~~~~~~~~~~~{:soso_e181:}{:soso_e181:}
12#
 楼主| 发表于 2016-8-21 16:29:22 | 只看该作者
wuheng 发表于 2015-1-22 08:43
可以,(本次附件为把字段改type......的表)字段可以增减、更改,我主要是要能把type以下的那些数据(如图 ...

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敬上
13#
 楼主| 发表于 2016-8-25 10:18:38 | 只看该作者
顶一下~~~~~~~~~~```各位大侠请援手~``谢谢
14#
 楼主| 发表于 2016-9-1 16:18:51 | 只看该作者
哪位大侠帮忙看看,施予援手~~~~`````谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-1 21:40 , Processed in 0.093477 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表