Python Forum
Updating sharepoint excel file odd results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating sharepoint excel file odd results
#1
So we display a excel file on our tv's in the office that has a embedded image on the sheet. I have a python script that updates that image daily. When this was implemented earlier this year, it worked like a charm and now noticed and was informed that it wasnt updating. So here is what im noticing and not sure how to change the code to help deal with this issue..

Script runs no errors or issues and when you look at the timestamp of the file, it shows it was modified at the scheduled time. When you open the file locally you see the updated image, BUT you also see a message at the top of the file that says there is a newer version. If you click on it and say you want to see the latest version, the updated image is removed and you see the image that was there before the update.

And because of this, the TV display never shows the updated image unless i open the file and reload the image manually.

#1 Is this common with sharepoint files?
#2 Is there a way to incorporate a delay between the update and the save to see if maybe its a timing issue?

I have noticed that on other files that we open from our teams server, if you make a change, you cant save it right away.. the "autosave" feature can take 2sec up to 10 sec to save. (this is in reference to manually opening and modifying files, not python)

Since i have noticed that when manually editing files, im wondering if that is the problem with trying to update via the script below.

import win32com.client
from pathlib import Path
from datetime import datetime, timedelta
import openpyxl

PricingVolumeFile = 'C:\\Users\\PricingVolumes2022.xlsx'

outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")
    
inbox = mapi.GetDefaultFolder(6)

inbox = mapi.GetDefaultFolder(6).Folders["Notifications"].Folders["Pricing"].Folders["Peak Future Volume"]

# THIS IS USED TO GRAB THE MESSAGE DATE SO IT CAN PROCESS ONLY THE LATEST EMAILS (EXAMPLE BELOW IS LAST 1 DAY)
received_dt = datetime.now() - timedelta(days=1)
received_dt = received_dt.strftime('%m/%d/%Y %H:%M %p')

edateFileSaveDate = datetime.now()
edateFileSaveDate = edateFileSaveDate.strftime('%Y%m%d')

messages = inbox.Items
messages = messages.Restrict("[ReceivedTime] >= '" + received_dt + "'")

for message in messages: 
    #     # THIS IS USED TO READ THE SUBJECT AND PARSE OUT THE DATE FOR THE APPROPRIATE MESSAGES
    sub = message.subject
    # TRY USING THIS ACTUAL MESSAGE DATE FOR THE IF CONDITION BELOW
    messD = message.ReceivedTime
    
    edDate = sub.split()[5]
    edreceived_dt = datetime.now()
    edreceived_dt = edreceived_dt.strftime('%m/%d/%Y %H:%M %p')
    tdDate = edreceived_dt.split()[0]      
    
    # CHECK IF MESSAGE IS TODAY SO THAT THE MOST CURRENT SCREENSHOT IS UPDATED IN THE FILE.
    if edDate == tdDate:
        attachments = message.Attachments
        # THIS ENSURES THAT THE EMAIL HAS AT LEAST 2 ATTACHMENTS BEFORE IT TRIES TO DOWNLOAD FILES THAT DONT EXIST    
        if attachments.count >= 1:
            
            #LOOP THRU ALL ATTACHMENTS AND ONLY DOWNLOAD CSV FILES
            for att in attachments:
               p = Path(str(att).lower())
               
               #newName = "{0}_{1}".format(p.stem,p.suffix)
               newName = edateFileSaveDate + "{0}".format(p.suffix)
               
               # CHECK IF ITS A PNG FILE BEFORE ATTEMPTING TO DOWNLOAD
               if p.suffix == ".png":
                  imgFileLoc = "C:\PricingVolume"+ '\\' + newName
                  # DOWNLOAD CSV FILE ONLY WITH THE NEW FILE NAME
                  figSaved  = att.SaveASFile(imgFileLoc)
                  #print(att)
                  # THIS IS THE MASTER EXCEL FILE THAT IS UPDATED AT THE END WITH THE FILTERED DATA
                  wrkb = openpyxl.Workbook()
                  ws = wrkb.worksheets[0]
                  img = openpyxl.drawing.image.Image(imgFileLoc)
                  img.height = 757
                  img.width= 1533
                  img.anchor = 'A1'
                  ws.add_image(img)
                  wrkb.save(PeakPricingVolumeFile)
    
    message.Unread = False
    message.Save()
Reply
#2
I think this is not a Python problem at all.

When we ran as MS Sharepoint back in the days, we could set permissions and workflows on a per-directory / folder base. E.g. anybody could upload a new revision of the file, but the file won't become visible to other user in the new revision unless somebody with the necessary rights approved the newer version (aka: made it public, so to speak). However, the person who uploaded the new revision always saw the new revision, independent of the appoval status. As far as I remember this was pretty much configurable up to complex workflows for the approval process.

Regards, noisefloor
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get all items in SharePoint recycle bin by using sharepy library in Python? QuangHuynh 2 351 Apr-10-2024, 03:09 PM
Last Post: SandraYokum
  Updating formulas in Excel - best solution MasterOfDestr 4 682 Mar-11-2024, 01:02 PM
Last Post: MasterOfDestr
  Python openyxl not updating Excel file MrBean12 1 342 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 455 Feb-07-2024, 12:24 PM
Last Post: Viento
  Search Excel File with a list of values huzzug 4 1,265 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,116 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 3,084 Feb-20-2023, 07:19 PM
Last Post: avd88
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 822 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Import XML file directly into Excel spreadsheet demdej 0 859 Jan-24-2023, 02:48 PM
Last Post: demdej
  how to read txt file, and write into excel with multiply sheet jacklee26 14 10,051 Jan-21-2023, 06:57 AM
Last Post: jacklee26

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020