Skip to content

Trying to get the SharePoint List Row data after pulling the header information. #970

Open
@Glmaxter

Description

@Glmaxter

Hi all,

I am trying to get the row data from a SharePoint list .

While I can get the field names, what I want after getting the field names is the row data to export it into excel.

Here is what I have from the example, and I have been looking at the lists of examples but not finding anything related to getting the field value and row data from it much less move it to excel. how would I go about doing this?

I have the site name and the view name.

`#Authentication
credentials = ClientCredential(client_secret, client_id)

site_url = "https://company.sharepoint.com/sites/RiskAssessment"
list_title = "Risk Assessment Workflow"
view_title = "1.4. Assign Work"

ctx = ClientContext(site_url).with_credentials(credentials)

list_object = ctx.web.lists.get_by_title(list_title)
#1. First request to retrieve view fields
view_fields = (
list_object.views.get_by_title(view_title).view_fields.get().execute_query()
)
#2. Second request to retrieve fields
fields = [
list_object.fields.get_by_internal_name_or_title(field_name).get()
for field_name in view_fields
]
ctx.execute_batch() # From performance perspective prefer execute_batch over execute_query here

fields_json = {f.internal_name: f.title for f in fields}
print(json.dumps(fields_json))`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions