I am attempting to open, read and use a macro and then re save an Excel file on Sharepoint using Python. Using the Office 365 REST-Python Client I can open and read but struggling to see how to do the rest.
Would appreciate any help, thanks!
`ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
response = File.open_binary(ctx, relative_url)
#save data to BytesIO stream
bio = io.BytesIO()
bio.write(response.content)
bio.seek(0) #set file object to start
#read file into pandas dataframe
df = pd.read_excel(bio, sheet_name="Overview")
print(df)
df.at[0,"Unnamed: 1"] = "description"
bio2 = io.BytesIO()
#pip install xlsxwriter
writer = pd.ExcelWriter(bio2)
df.to_excel(writer, sheet_name="Overview")
writer.save()
bio2.seek(0)
df = pd.read_excel(bio2, sheet_name="Overview")
workbook = bio2.read()
response2 = File.save_binary(ctx, relative_url, workbook)
print(response2)`