0

I have a dataframe that I want to export to an existing Excel file that exists online on my company's sharepoint. I have the following line of code to do this:

df.to_excel(r'Path where the exported excel file will be stored\File Name.xlsx', sheet_name='Your sheet name', index = False) The filepath starts with https and ends with a filetype .xlsx?web=1

Python of course doesn't recognise .xlsx?web=1 as a valid filetype so do I just ignore the ?web=1 at the end? This is what I did but get an access denied error. What do I need to do to be able to export to this file?

Edit: Filepath is https://companyname.sharepoint.com/sites/XXX/Shared%20Documents/07%20-%20LE%20(Loss%20Elimination)/02%20-%20Open%20(Current)%20Loss%20Elimantions/13%20-%20Material%20loss%20against%20BOM/Copy_Material%20Flow%20for%20HDW%20Euro%20When%20to%20FP.xlsx?web=1

2
  • ?web=1 , is not part of the file path ... we need to know what 'Path were the file is stored' looks like. Are you entering a URL or a UNC filepath to a mapped drive? Commented Jan 19, 2022 at 10:51
  • This is the full link: companyname..sharepoint.com/sites/XXX/Shared%20Documents/… @JeffUK Commented Jan 19, 2022 at 11:12

1 Answer 1

2

The filepath starts with https and ends with a filetype .xlsx?web=1

That's not a path, that's a URL. You cannot simply "save" to a URL.

There are Python libraries for working with sharepoint. For example Office365-REST-Python-Client, pysharepoint and this one on pypi, but the latter only seems to support downloading, not uploading.

Since pysharepoint is basically a front-end for SharePlum, you might want to look at that as well. It comes with documentation.

Sign up to request clarification or add additional context in comments.

7 Comments

I've edited the post with what I believe is the filepath? It was just copied straight from the excel document. I'll take a look at that library though, thanks.
While the libraries are useful, I would start with trying to map a network drive to the sharepoint library, then you can treat it as a file and let the OS handle the rest. (Not sure this works.. but I think it's worth trying!)
Thanks @JeffUK. Seems like a much simpler option but I get an error saying "Permission denied". Guess I need to authenticate it somehow...
@JeffUK This actually came up in a different stackoverflow answer. But it was commented on as "not working".
@XYZ123 Also look at the pysharepoint library to which I added a link. It seems quite easy to use.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.