[英]Not able to read Sharepoint list items which has blanks in its headers
I am using Sharepoint online to fetch the data from the list.我正在使用 Sharepoint 在线从列表中获取数据。 For that I have written below code:
为此,我编写了以下代码:
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"])
For the headers in the sharepoint list which contains like single word in header it is populating values but which headers have space in it like "Project ID", "Process Owner".对于共享点列表中的标题,它在标题中包含类似的单个单词,它正在填充值,但哪些标题中有空格,如“项目 ID”、“流程所有者”。 It is giving error
KeyError: 'Project ID'
.它给出了错误
KeyError: 'Project ID'
。
Can somebody help me to know how we can get values for those headers which have space in their names or underscore(i tried to replace space with underscore still not working) or can we print l_items
to know how it is saving column headers with space or underscore.有人可以帮助我了解如何获取名称或下划线中有空格的标题的值(我尝试用下划线替换空格仍然无效),或者我们可以打印
l_items
以了解它如何使用空格保存列标题或下划线。
Hi i got the answer for it.嗨,我得到了答案。 If you have space or underscore in headers just write without space in header for example:-
如果标题中有空格或下划线,则只需在标题中没有空格的情况下写入,例如:-
for item in l_items:
print(item.properties['ProjectID'], item.properties['ProcessOwner'])
This worked for me.这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.