Add new data to existing SharePoint xlsx files - python

I would like to write into an existing xlsx file in SharePoint. Is that even possible? Mydata is in the form of a dataframe and if possible, just append the dataframe instead of overwriting the whole xlsx file. I tried to use xlsxwriter library but did not get anywhere. Any help would be appreciated

#Coder123,
As you're using SP Online, you could update the content of xlsx file stored in SPO via MS Graph API:
https://learn.microsoft.com/en-us/graph/api/table-update?view=graph-rest-1.0&tabs=http
through this API, you can update the table/worksheet of an xlsx file. And it has offered a python library:
https://github.com/microsoftgraph/msgraph-sdk-python-core

Related

Is there any workaround to save csv with multiple sheets in python

I'm currently working with a pandas data frame and need to save data via CSV for different categories.so I thought to maintain one CSV and add separate sheets to each category. As per my research via CSV, we can't save data for multiple sheets. is there any workaround for this? I need to keep the format as CSV(cant use excel)
No.
A CSV file is just a text file, it doesn't have a standard facility for "multiple sheets" like spreadsheet files do.
You could save each "sheet" as a separate file, but that's about it.

How to have a pandas DATAFRAME saved into a SHAREPOINT as csv file?

I have a DataFrame that I would like to store as a CSV file in a Sharepoint.
It seems that the only way is to first save CSV file locally and then, using Shareplum, upload file to Sharepoint.
Is there a way to directly save DataFrame into Sharepoint as CSV file, without creating a local file?
Thanks a lot for your help.
It should be possible to write the csv content to an in-memory text buffer (e.g. StringIO or ByteIO) rather than to a local file - here is an example (last section of the page).
After that, you could use a library for writing the content directly to a Sharepoint: This discussion shows several approaches how to do that, including the Office365-REST-Python-Client and also SharePlum, which you have already mentioned.
Here are two more sources (Microsoft technical doc) that you might find useful:
How can I upload a file to Sharepoint using Python?
How to get and upload files from sharepoint with python?

How can I update workbook links when using pd.read_excel()?

The question is pretty simple, actually.
I'm reading an Excel file using Pandas. When I open it using Office's Excel in my Desktop I'm prompted to Enable Content and then Update Links [that is, update values in those cells importing information from cells in other workbooks and xslx files], so it reads other files in some other folders.
While using pd.read_excel('filename') however that option is not available, and I'm afraid it's importing the data previously contained in the spreadsheet without updating it. Is there a workaround?

Fetch defined_names from a .xls file

I'm trying to fetch tagged data from a .xls file.
I am able to fetch the tagged data from .xlsx file using Openpyxl, like this: [dn for dn in wb.defined_names.definedName]
But openpyxl does not support .xls format and I need to get the defined_names from .xls file as well.
Is there any library that can read .xls and return the defined_names in the file?
check xlrd package.
Here is the relevant part of the docs - Named references, constants, formulas, and macros

How do I read/write both xlsx and xls files in Python?

I have a web application (based on Django 1.5) wherein a user uploads a spreadsheet file.
I've been using xlrd for manipulating xls files and looked into openpyxl which claims to support xlsx/xlsm files.
So is there a common way to read/write both xls and xlsx files?
Another option could be to convert the uploaded file to xls and use xlrd. For this I looked into gnumeric and ssconvert, this would be favorable since all my existing code in written using xlrd and I will not have to change the existing codebase.
So should I change the library I use or go with the conversion solution?
Thanks in advance.
xlrd can read both xlsx and xls files, so it's probably simplest to use that. Support for xlsx isn't as extensive as openpyxl but should be sufficient.
There's a risk of losing information in converting xlsx to xls because xlsx files can be much larger.

Categories

Resources