Невозможно получить значение, если тип столбца sharepoint "Person" - Python - PullRequest
0 голосов
/ 04 марта 2020

Я пытаюсь извлечь список из Sharepoint. Дело в том, что если тип столбца «Персона или группа» Python, покажите мне KeyError, но если тип столбца отличается, я могу его получить.

Column types in SharePoint

Это мой код для получения значений:

print("Item title: {0}, Id: {1}".format(item.properties["Title"], item.properties['AnalystName']))

И Title работает, но AnalystName - нет. оба являются внутренними именами в sharepoint.

1 Ответ

0 голосов
/ 05 марта 2020
authcookie = Office365('https://xxxxxxxxx.sharepoint.com', username='xxxxxxxxx', password='xxxxxxxxx').GetCookies()
site = Site('https://xxxxxxxxxxxx.sharepoint.com/sites/qualityassuranceteam', authcookie=authcookie)
new_list = site.List('Process Review - Customer Service Opt In/Opt Out')
query = {'Where': [('Gt', 'Audit Date', '2020-02-16')]}
sp_data = new_list.GetListItems(fields=['App ID', 'Analyst Name', 'Team Member Name', "Team Member's Supervisor Name",
                                        'Audit Date', 'Event Date (E.g. Call date)', 'Product Type', 'Master Contact Id',
                                        'Location', 'Team member read the disclosure?', 'Team member withheld the disclosure?',
                                        'Did the team member take the correct action?', 'Did the team member notate the account?',
                                        'Did the team member add the correct phone number?', 'Comment (Required)',
                                        'Modified'], query=query)
#print(sp_data[0])

final_file = '' #Create an empty File
num = 0
for k in sp_data:
    values = sp_data[num].values()
    val = "|".join(str(v).replace('None', 'null') for v in values) + '\n'
    num += 1
    final_file += val
file_name = 'test.txt'
with open(file_name, 'a', encoding='utf-8') as file:
     file.write(final_file)

Итак, сейчас я получаю то, что хочу, но есть проблема. Когда столбец пуст, он пропускает столбец, а не выводит пустое место. например:


col-1 | кол-2 | col-3 |

HI | 10 | 8 |

Привет | | 7 |

Итак, в этой таблице строка 1 заполнена, поэтому она принесет мне все что угодно: HI | 10 | 8, но вторая строка принесет мне Hello | 7, и мне нужен Hello || 7

...