新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     >>W3CHINA.ORG讨论区<<     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> XML网站展示,XML源代码,XML编程示例。 本版仅接受原创、转贴、网站展示,具体的技术交流请前往各相关版块。
    [返回] W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWLXML.ORG.CN讨论区 - XML技术『 XML源码及示例(仅原创和转载) 』 → 一个烦恼的问题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 4628 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 一个烦恼的问题 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     tony3376 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:59
      门派:XML.ORG.CN
      注册:2007/7/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给tony3376发送一个短消息 把tony3376加入好友 查看tony3376的个人资料 搜索tony3376在『 XML源码及示例(仅原创和转载) 』的所有贴子 引用回复这个贴子 回复这个贴子 查看tony3376的博客楼主
    发贴心情 一个烦恼的问题

    最近一个项目中,需要利用excel访问webservice,读出数据库内容(webservice已与数据库连接好)后,把得到的数据填充到excel中,并在客户端生成一个xml文件记录所读取内容。

    现在我做的vba已经可以访问webservice,但是不能填充数据到excel,并且生成的xml文件缺少<?xml version="1.0" standalone="yes"?>。请问该如何解决??

    附有vba代码:

    sheet1代码
    'Alok Mehta
    'MSDN VBA Excel-WebService Example Code

    Option Explicit
    'WebService Dataset will be temporarily saved in the following XML file
    Const XMLFileName = "C:\wd22.xml"

    'Professor will be given the following two IDs by the the IT department, these can also be tied to WS tokens
    Const Course_ID = 1
    Const Professor_ID = 1

    Private Sub cmdGetDataFromWebService_Click()
             'On Error GoTo Error_Processing
            
            Dim objGrades As New clsws_Service
            Dim strReturnValue As String
            Dim bSaveFile As Boolean
            
            'Local Counters
            Dim intI As Integer
            Dim intJ As Integer
            Dim intOffset As Integer
            intOffset = 5 ' Starting Row
            
            Dim strColumn As String
            Dim strValue As String
            Dim strFieldName As String
            Dim oRoot As MSXML2.IXMLDOMNode
            Dim NewXMLdocument As New MSXML2.DOMDocument
            
            strReturnValue = objGrades.wsm_Get_Grades(Professor_ID, Course_ID)
            
            'Save the Returned XML to disk
            bSaveFile = SaveToXML(XMLFileName, strReturnValue)
            MsgBox strReturnValue
            'If the file is saved
            If bSaveFile Then
                'Load it in Memory
                Call NewXMLdocument.Load(XMLFileName)
                Set oRoot = NewXMLdocument.documentElement
                
                'Iterate through all the nodes
                For intI = 0 To oRoot.childNodes.Length - 1
                     For intJ = 0 To oRoot.childNodes.Item(intI).childNodes.Length - 1
                     
                         strValue = oRoot.childNodes.Item(intI).childNodes.Item(intJ).Text
                         strFieldName = oRoot.childNodes.Item(intI).childNodes.Item(intJ).baseName
                         
                         'Map the database fieldanme to the Spreadsheet Cells
                         Select Case strFieldName
                                Case "ProductID"
                                     strColumn = "A"
                                Case "Pname"
                                     strColumn = "C"
                                Case "content"
                                     strColumn = "D"
                                Case "author"
                                     strColumn = "E"
                         End Select
                         
                        
                         'Set the cell's value to XML's node
                         If IsNull(strValue) = False Then
                            ActiveSheet.Cells(intI + intOffset, strColumn).Value = strValue
                         End If
                         Debug.Print strFieldName, strValue
                     Next
                Next
                
                'Show that we are done
                MsgBox "Web Service Data Get was successful"
            End If
            
            Set objGrades = Nothing
            Exit Sub
            
    Error_Processing:
            MsgBox "Error in Web Service Data Get " & Err.Description
    End Sub

    Private Function SaveToXML(strValue As String, strFileName As String) As Boolean
            On Error GoTo Error_Processing
            
            Dim fs As Object
            Dim a
            
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set a = fs.CreateTextFile(strValue, False)

            a.WriteLine (strFileName)
            a.Close
            SaveToXML = True
            Exit Function
    Error_Processing:
            
            MsgBox "Cannot Save XML File " & Err.Description
            SaveToXML = False
    End Function

    类模块代码:
    'Dimensioning private class variables.
    Private sc_Service As SoapClient30
    Private Const c_WSDL_URL As String = "http://localhost:1784/testexcel/Service.asmx?wsdl"
    Private Const c_SERVICE As String = "Service"
    Private Const c_PORT As String = "ServiceSoap"
    Private Const c_SERVICE_NAMESPACE As String = "http://myCollege.edu/"

    Private Sub Class_Initialize()
        '*****************************************************************
        'This subroutine will be called each time the class is instantiated.
        'Creates sc_ComplexTypes as new SoapClient30, and then
        'initializes sc_ComplexTypes.mssoapinit2 with WSDL file found in
        'http://localhost/grades/WebService.asmx?wsdl.
        '*****************************************************************

        Dim str_WSML As String
        str_WSML = ""

        Set sc_Service = New SoapClient30

        sc_Service.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
        'Use the proxy server defined in Internet Explorer's LAN settings by
        'setting ProxyServer to <CURRENT_USER>
        sc_Service.ConnectorProperty("ProxyServer") = "<CURRENT_USER>"
        'Autodetect proxy settings if Internet Explorer is set to autodetect
        'by setting EnableAutoProxy to True
        sc_Service.ConnectorProperty("EnableAutoProxy") = True


    End Sub

    Private Sub Class_Terminate()
        '*****************************************************************
        'This subroutine will be called each time the class is destructed.
        'Sets sc_ComplexTypes to Nothing.
        '*****************************************************************

        'Error Trap
        On Error GoTo Class_TerminateTrap

        Set sc_Service = Nothing

    Exit Sub

    Class_TerminateTrap:
        ServiceErrorHandler ("Class_Terminate")
    End Sub

    Private Sub ServiceErrorHandler(str_Function As String)
        '*****************************************************************
        'This subroutine is the class error handler. It can be called from any class subroutine or function
        'when that subroutine or function encounters an error. Then, it will raise the error along with the
        'name of the calling subroutine or function.
        '*****************************************************************

        'SOAP Error
        If sc_Service.FaultCode <> "" Then
            Err.Raise vbObjectError, str_Function, sc_Service.FaultString
        'Non SOAP Error
        Else
            Err.Raise Err.Number, str_Function, Err.Description
        End If

    End Sub

    Public Function wsm_Get_Grades(ByVal dcml_nProfessorID As Double, ByVal dcml_lngCourseID As Double) As String
        '*****************************************************************
        'Proxy function created from http://localhost/grades/WebService.asmx?wsdl.
        '
        '"wsm_Get_Grades" is defined as XML. See Complex Types: XML Variables in
        'Microsoft Office 2003 Web Services Toolkit Help for details on implementing XML variables.
        '*****************************************************************

        'Error Trap
        On Error GoTo wsm_Get_GradesTrap

        wsm_Get_Grades = sc_Service.Get_Grades(dcml_nProfessorID, dcml_lngCourseID)

    Exit Function
    wsm_Get_GradesTrap:
        ServiceErrorHandler "wsm_Get_Grades"
    End Function


    麻烦大家帮忙下,很着急。谢谢各位


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/7/31 1:34:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML源码及示例(仅原创和转载) 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/22 19:47:14

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    375.000ms