【问题标题】:Not able to read Sharepoint list items which has blanks in its headers无法读取标题中有空格的 Sharepoint 列表项
【发布时间】:2021-09-28 22:43:52
【问题描述】:

我正在使用 Sharepoint 在线从列表中获取数据。为此,我编写了以下代码:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.user_credential import UserCredential


baseurl = 'https://my.org.com'
basesite = '/teams/ia/Powerappsdatabase/' # every share point has a home.
siteurl = baseurl + basesite
sp_list = "HCFM_Projects"
ctx = ClientContext(siteurl).with_credentials(UserCredential("id@org.com", "password"))
sp_lists = ctx.web.lists
s_list = sp_lists.get_by_title(sp_list)
l_items = s_list.get_items()
ctx.load(l_items)
ctx.execute_query()

for item in l_items:
    print(item.properties['Title'], item.properties['Owner'], item.properties["Status"])

对于共享点列表中包含类似标题中的单个单词的标题,它正在填充值,但哪些标题中有空格,例如“项目 ID”、“流程所有者”。它给出了错误 KeyError: 'Project ID'.

有人可以帮我了解如何获取名称或下划线中有空格的标题的值(我尝试用下划线替换空格仍然无效)或者我们可以打印l_items 以了解它是如何节省的带有空格或下划线的列标题。

【问题讨论】:

    标签: python sharepoint office365 sharepoint-online sharepoint-list


    【解决方案1】:

    嗨,我得到了答案。如果标题中有空格或下划线,只需在标题中不带空格即可,例如:-

    for item in l_items:
        print(item.properties['ProjectID'], item.properties['ProcessOwner'])
    

    这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 2015-02-16
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多