码迷,mamicode.com
首页 > 编程语言 > 详细

【Sharepoint工具】Excel宏读取Sharepoint列表数据(VBA)

时间:2015-05-18 10:44:35      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

第一、开发原因:

某些时候Sharepoint列表的操作并不方便,比如数据量大,需要批量处理数据的时候。通过服务器代码有太多限制,比如智能通过B/S发送给用户,速度慢且影响服务器性能。
客户端代码同样有一些慢。

第二、具体界面:

技术分享

技术分享

第三具体代码:

Private Sub GetListBut_Click()
On Error GoTo ErrorHandler
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set clsMossHelper = New CMossHelper
    Dim myTable As ListObject
    Dim myRow As ListRow
    Dim listName As String
    Dim xmlDoc As MSXML2.domDocument
    Dim xmlNode As MSXML2.IXMLDOMNode
    Dim xmlAttribute As MSXML2.IXMLDOMAttribute
    Set myTable = ActiveWorkbook.Sheets("Sheet1").ListObjects("Table1")
    
    clsMossHelper.Init "AAA", "http://AAA:222/yixiaozi"
    listName = "ABC"
    
    Dim viewName As String
    ForToolUpdate
    viewName = "{f5022e21-7a8d-40c1-b327-d9db9e227f33}"
    viewName = "{324DD64B-ED68-4E86-83D0-321E1AB2D403}"
    
    For Each myRow In myTable.ListRows
        
        Dim query As String
        
        query = "<query><Query><Where><Eq><FieldRef Name=‘Title‘ /><Value Type=‘Text‘>"
        query = query & myRow.Range.Columns(1).Value
        query = query & "</Value>"
        query = query & "</Eq></Where></Query></query>"
        
        query = "<query><Query><Where><And><Eq><FieldRef Name=‘Title‘ /><Value Type=‘Text‘>"
        query = query & "a"
        query = query & "</Value>"
        query = query & "</Eq><Eq><FieldRef Name=‘description‘ /><Value Type=‘Text‘>"
        query = query & "2"
        query = query & "</Value></Eq></And></Where></Query></query>"
        
        Dim blnFlag As Boolean
        Dim errorMsg As String
        Dim retData As String
          
        blnFlag = clsMossHelper.GetListItems(listName, viewName, query, retData, errorMsg)
        If blnFlag = True Then
             
             
            Set xmlDoc = New MSXML2.domDocument
            
            xmlDoc.LoadXML retData
            For Each xmlNode In xmlDoc.SelectNodes("//rs:data/z:row")
            Dim description
            
            Set description = xmlNode.Attributes.getNamedItem("ows_description")
                
                If description Is Nothing Then
                    description = ""
                Else
                    description = description.Text
                End If
                
               myRow.Range.Columns(2).Value = description
            Next
        Else
            MsgBox errorMsg
        End If
    Next
    Set xmlAttribute = Nothing
    Set xmlNode = Nothing
    Set xmlDoc = Nothing
    
    Set clsMossHelper = Nothing
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
    MsgBox "OK"
Exit Sub

ErrorHandler:
          
    If Not xmlAttribute Is Nothing Then
        Set xmlAttribute = Nothing
    End If
    
    If Not xmlNode Is Nothing Then
        Set xmlNode = Nothing
    End If
    
    If Not xmlDoc Is Nothing Then
        Set xmlDoc = Nothing
    End If
    
    If Not clsMossHelper Is Nothing Then
        Set clsMossHelper = Nothing
    End If
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
    MsgBox Err.description
    

End Sub

第四:Excel文件。

http://files.cnblogs.com/files/yixiaozi/getListData.zip

【Sharepoint工具】Excel宏读取Sharepoint列表数据(VBA)

标签:

原文地址:http://www.cnblogs.com/yixiaozi/p/4511218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!