【问题标题】:SharePoint Lists, GetListItems, XML, and VBA - I just want to crossreference!SharePoint 列表、GetListItems、XML 和 VBA - 我只想交叉引用!
【发布时间】:2010-10-01 12:15:05
【问题描述】:

我有一个 SharePoint 列表,其中包括我关心的两列;在 Excel-ese 中,我想匹配第 1 列中的值 X,并在第 2 列中返回相应的值。我可以在 http://guruj.net/node/63 处使用代码的 variant 来检索信息(我认为),所以我认为我的问题集中在在没有下载 DLL 的情况下在 VBA 中导航 XML(我确实有一堆 MSXML?.DLL,2、2.6、3、4、5、6)。

我找到的最接近的 MSDN 文章参考 .NET(我卡在 Office 2003 附带的 VBA/VB6 中?)或可下载的 DLL。

Nat 在下面的回复概述了我发现或需要的大部分内容就像我发现它的语言有误,我的部分问题是查找搜索词。我拼凑了一些翻译,例如,XMLDocument 似乎是 DOMDocument,但 XML 部分是 IXMLDOMNode 或类似的。

我目前遇到的主要问题是执行查询的 SOAP 调用出现类型不匹配,或者当我尝试重铸播放器时对象不支持该方法(listQuery、listViewFields、listQueryOptions )。我将各个部分保留为变体,然后将它们转换为返回的类型(因为我没有“引用”特定于 SP 的库,所以我这样做有点盲目)并且得到了不匹配。

屏幕抓取文本似乎要容易得多。

【问题讨论】:

    标签: xml sharepoint vba


    【解决方案1】:

    哇,你在兔子洞里这么远......

    好的,您正在查看的代码让您在 SharePoint 列表上查看,这可能不是最好的起点,但是这一切都是在 VBA 中完成的,这使得它非常困难。我有 .NET C# 代码来查询列表并检索具有特定值的项目。我无法进行的 VBA 转换。

    public static string GetPageId(string listName, string webPath, string pageTitle)
        {
            string pageId = "";
            IntranetLists.Lists lists = new IntranetLists.Lists();
            lists.UseDefaultCredentials = true;
            lists.Url = webPath + "/_vti_bin/lists.asmx";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + pageTitle + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
            XmlNode listQuery = doc.SelectSingleNode("//Query");
            XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
            XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
    
            Guid g = GetWebID(webPath);
    
            XmlNode items = lists.GetListItems(listName, string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString());
            foreach (XmlNode listItem in SPCollection.XpathQuery(items, "//sp:listitems/rs:data/z:row"))
            {
                XmlAttribute id = listItem.Attributes["ows_Id"];
                if (id != null)
                {
                    pageId = id.Value;                    
                }
    
            }
            return pageId;            
        }
    

    IntranetLists 是对 lists.asmx 文件的 .net Web 引用。

    您必须研究如何在 VBA 中使用 lists.asmx Web 服务, 然后,您必须使用表示您要查找的列值的查询来调用 GetListItems。

    <Where><Contains><FieldRef Name="Title" /><Value Type="Text">MyValue</Value></Contains></Where>
    

    该查询的语法是CAML

    那么您将不得不解析返回的 xml 以找到具有您需要的值的项目和项目字段。 任何 xpath 查询都必须添加正确的命名空间,例如

      public static XmlNodeList XpathQuery(XmlNode xmlToQuery, string xPathQuery)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlToQuery.OuterXml);
            XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable);
            mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
            mg.AddNamespace("z", "#RowsetSchema");                                   
            mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
            mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
            mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
            mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");
            return doc.SelectNodes(xPathQuery, mg);
        }
    

    但是我不确定您是否可以访问在您的 VBA 设置中解析 xml 的内容,因此您可能需要下载一些额外的 VBA 工具来执行此操作 - 甚至可能会被阻止。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-15
      • 1970-01-01
      • 2017-04-03
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多